BookmarkSubscribeRSS Feed
DesmondSas715
Calcite | Level 5

Need help with separating Full_Name 'Jon Joshua M' as Last_name 'Jon', 'First_name' Joshua, 'Middle_Initial' M.

3 REPLIES 3
Kathryn_SAS
SAS Employee

You can use the SCAN function to do this. This assumes that the delimiter is a space and that the name is always in the same order: last first middle.

data test;
full_name='Jon Joshua M';
last_name=scan(full_name,1,' ');
first_name=scan(full_name,2,' ');
middle_initial=scan(full_name,3,' ');
run;

proc print;
run;
PaigeMiller
Diamond | Level 26

It also assumes that names always follow a pattern, but how about a Dutch name where the last name is Van Aalen?

 

Van Aalen Sarah G

 

and then the rules to find last name as the first "word" fail.

--
Paige Miller
SASKiwi
PROC Star

FYI, SAS Data Quality has name parsing algorithms that cater for national differences to do the splitting you want. Of course this is more geared to enterprise-wide solutions as opposed to individual requirements.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 440 views
  • 0 likes
  • 4 in conversation