BookmarkSubscribeRSS Feed
ren2010
Obsidian | Level 7
Hi,

I have a situation,where i have a variable NAME
eg:
NAME
----------
JOHN C MAT,MD
SARA ATIO,MD

I would like to seperate this name as Fname,MIDname,Lname
so my output look like
Fname MIDname Fname
---------------------------------------------------
JOHN C MAT,MD
SARA ATIO,MD

Please let me know,if you have a solution for this.

thanks,
Ren
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi:
There are a number of character string functions -- the simple ones, like SCAN and SUBSTRING and FIND and INDEX and the more complex ones, like the Perl Regular Expression which would allow you to break up a string into chunks.

There's a simple example at the end of this post. If you don't have regular names (maybe 1 middle name, maybe 2 middle names, possible space before MD, maybe not, maybe 2 credentials), then you may want to go down the Perl Regular Expression road. There have been many postings in the Forum on splitting up text strings.

As you can see from the log results of this program (with the Big Bird, Yellow) results, the SCAN approach only lends itself to very regular data.

cynthia
[pre]
data break_it_up;
length name $30;
infile datalines dsd;
input name $;
first = scan(name,1,' ');
middle = scan(name,2,' ');
last = scan(name,3,' ');
suffix = scan(name,4,', ');
if last = ' ' then do;
** takes care of no middle name;
last = middle;
middle = ' ';
end;
put "*************************************************";
put (_all_) (=);
return;
datalines;
"Kermit The Frog,Esq."
"Oscar The Grouch, GC"
"Miss Piggy"
"Big Bird, Yellow"
;
run;


LOG RESULTS from PUT statements:
*************************************************
name=Kermit The Frog,Esq. first=Kermit middle=The last=Frog,Esq. suffix=Esq.
*************************************************
name=Oscar The Grouch, GC first=Oscar middle=The last=Grouch, suffix=GC
*************************************************
name=Miss Piggy first=Miss middle= last=Piggy suffix=
*************************************************
name=Big Bird, Yellow first=Big middle=Bird, last=Yellow suffix=
NOTE: The data set WORK.BREAK_IT_UP has 4 observations and 5 variables.

[/pre]
ren2010
Obsidian | Level 7
Thanks Cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 652 views
  • 0 likes
  • 2 in conversation