Need help with separating Full_Name 'Jon Joshua M' as Last_name 'Jon', 'First_name' Joshua, 'Middle_Initial' M.
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;
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.
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.