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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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