11-04-2015 10:37 PM
I need to separate first name and last name which do not have any delimiter specified.
I have the following data set:
input name : $20.;
I need a dataset from the above dataset with ouput as:
|first name||last name|
how should I get the above data set??
11-04-2015 11:15 PM
If there is no rule or pattern you can describe that identifies where the word boundaries are then there is no way to program it in SAS or any other computer language.
The only way I suspect this would work is if your software had access to an appropriate database of surnames and first names and you were able to do name matches. This is definitely not available in Base SAS.
11-05-2015 08:51 AM
For this small table you can use multiple IFs and substr function to separate what you need.
But if your table is very large and there is no patterns, then you need a new way to get this table
I agree with Kiwi.
But for this small table you can do this:
data want_&name(where=(last_name ne ""));
if substr(name,1,1) = "&name." then do;
last_name = substr(name,&pos. ,&len.);
first_name = substr(name,&pos1.,&len1.);
And then append.
Hope this helps
11-05-2015 09:41 AM
Agree with everyone above. Even something as simple as capital letter for each first and last name would help. Anything to determine the start position of each name element (including middle initials if there are any).
So if you altered the data in any way to make them all lowercase, then maybe you have the information you need, otherwise, you will need to request a new file with the appropriate delimiters.
11-06-2015 01:18 AM
11-06-2015 10:36 AM
It is possible that what you presented was not exactly what the interviewer asked or the data example you provided had some difference.
A very minor change such as the name parts starting with a capital letter would make it possible.