Hi all,
I've got an inconsistent list of names that I need to separate into last name and first name. I've used SCAN and SUBSTR before but I'm having trouble this time. Here's an example of the data I have in a variable called NAME:
AMY
CHLOE, GREG
LING, DANIEL
RAZICK, OMAR
VELJANI, JOVI (JOHN)
ALFASA
So obviously they aren't entirely consistent. I am just trying to pull out the first word because I need to match up some pre-post assessments that the same people took and I can do that roughly using last name. In the cases where the person only put their first name they put it that way both times, so I will have to assume that AMY pre is the same as AMY post.
My code, trying both SUBSTR and SCAN, where a comma and a space are the possible delimiters:
data pre;
set pre;
lastname=substr(name,1);
lastname2=scan(name,1,', ');
run;
both SUBSTR and SCAN functions in this form give me the same error:
"NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 144:14 NOTE: Invalid numeric data, 'AMY' , at line 144 column 14. RESPONDENTID=123456789
...
NAME=AMY
...
"
Why is it trying to convert character to numeric then tell me the name isn't numeric? Is it because my first observation contains a single word rather than two words? In that case I would expect it to behave exactly like Example 1 here: http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p0jshdjy2z9zdzn1h7k90u99lyq6.htm Here there is an entry of a single word ("Leonardo") and it comes out of the SCAN function as the first and the last word, where in my situation it won't do anything.
SAS 9.4 on Windows server
... View more