BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GreggB
Pyrite | Level 9

The data I have (in one field):

Name 

Doe,  John  M. 

The data I want (in 3 fields):

Last     First     Mi

Doe     John     M

1 ACCEPTED SOLUTION

Accepted Solutions
CTorres
Quartz | Level 8

Very simplistic but works if there are no composed names, prefixes, more than one initial, etc...:

data have;

  name='Doe, John M';

  last=scan(name,1);

  first=scan(name,2);

  Mi=scan(name,3);

run;

CTorres

View solution in original post

4 REPLIES 4
CTorres
Quartz | Level 8

Very simplistic but works if there are no composed names, prefixes, more than one initial, etc...:

data have;

  name='Doe, John M';

  last=scan(name,1);

  first=scan(name,2);

  Mi=scan(name,3);

run;

CTorres

GreggB
Pyrite | Level 9

Simplistic works for me!  Thanks.

ballardw
Super User

Beware of two word last names such as Le Blank, Van Dorp and such.

You might want to run a word count to see if you have more than 3 words in the field to bring possible problems to your attention.

dcruik
Lapis Lazuli | Level 10

I'm not sure how dynamic you need the code to be, whether your Name field is consistent or not with the length of the Middle Initial and whether there are more than two names for the first name, but this code will help with your example you gave.

data have;

input name $25.;

datalines;

Doe, John M.

;

run;

data want;

set have;

format Last First $15. FirstMi $20. Mi $1;

Last=scan(Name,1,",");

FirstMi=scan(Name,2,",");

First=strip(scan(FirstMi,1," "));

Mi=compress(scan(FirstMi,2," "),".");

drop FirstMi;

run;

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
  • 4 replies
  • 846 views
  • 0 likes
  • 4 in conversation