Hi All,
I know this is a very stupid question to ask, but I am bit confused with the following:
How can I get the First Name and Middle Name in the same column and Last name in a different column?
As I don't have double space before the last name so I can't use '&' in my INPUT statement.
Data Sample;
Input First_name $ Last_Name;
Cards;
Nadal Anthony Samuel
John Beth Goodrich
;
Run;
Result:
First_Name Last_Name
Winston Anthony Samuel
John Beth Goodrich
Thanks for your help!
I'm sure there are a number of ways to do it. If you ALWAYS have first and middle names then you could use something like:
Data Sample (drop=Middle_name);
length First_name $30.;
informat First_name Middle_name Last_Name $15.;
input First_name Middle_name Last_Name;
First_name=catx(' ',First_name,Middle_name);
cards;
Nadal Anthony Samuel
John Beth Goodrich
;
I'm sure there are a number of ways to do it. If you ALWAYS have first and middle names then you could use something like:
Data Sample (drop=Middle_name);
length First_name $30.;
informat First_name Middle_name Last_Name $15.;
input First_name Middle_name Last_Name;
First_name=catx(' ',First_name,Middle_name);
cards;
Nadal Anthony Samuel
John Beth Goodrich
;
This is actually a difficult problem to handle properly as some last names include spaces.
data sample;
input @ ;
length first_name $50 last_name $50 ;
last_name = scan(_infile_,-1,' ');
first_name = substr(_infile_,1,length(_infile_)-length(last_name));
cards;
Nadal Anthony Samuel
John Beth Goodrich
;
Run;
is there always just one middle name?
how often might a "last name" be more than one word (not counting double-barrelled surnames separated with a ( - ) hyphen )?
I have two middle names. Should both follow my first name?
@Art and @Tom - Thanks for sharing the knowledge.
@Peter, Well it depends on the business rules and requirements. I was writing some code and came up with this and was not able to think clearly on the solution. So that's the reason I came up with this question.
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.
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.