Hi all,
I am working with data sets which have names like
Nichols, KregFIReddy, RamanaBTAnd I have to find the first name as Kreg and Ramana. pls, can anyone help me how to find it?I was trying with this code SUBSTR(name,LENGTH(name,",")-1, -2); . but it was giving me an error.
data have;input custname:$15.;datalines;Nichols,KregFIReddy,RamanaBT;run;
data want;set have;first_name = substr(scan(custname,-1,','),1,length(scan(custname,-1,','))-2);run;
View solution in original post
If it's always two characters that need to be cut away, do this:
data have; input name $30.; datalines; Nichols, KregFI Reddy, RamanaBT ; data want; set have; firstname = scan(substr(name,1,length(name)-2),2,','); run; proc print data=want noobs; run;
Result:
name firstname Nichols, KregFI Kreg Reddy, RamanaBT Ramana
Thanks.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Latest Updates
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.