I don't know how to revise the third argument that is producing the error message. It is referring to the line bolded below. Any suggestions much appreciated.
if indexw(name_last,' AKA ') then do;
alias=strip(strip(alias)||"/"||substr(name_last,(indexw(name_last,'AKA')+4)));
if index(alias,"/")=1 then alias=compress(alias,"/");
name_last=substr(name_last,1,indexw(name_last,'AKA')-1);
end;
Cheers!
Use SUBSTRN() instead of SUBSTR() .
Hi @elli444
This happens if AKA is the first word in last_name. Then indexw returnns 1, and the third argument becomes 0, which is illegal.
What should happen in this case? - last_name left unchanged or last_name set empty?
We'd prefer the last name left unchanged.
Hi @elli444
I think this small modification (check for indexw > 1) will work. The problem with your code is that indexw ignores blanks. Even if you specify indexw(' AKA '), it treats is as 'AKA', so the condition vill be true also if name_last starts with AKA.
data have;
infile datalines truncover;
input name_last $char50.;
datalines;
Hansen AKA Hans
AKA Dummy
Saint George AKA Dragon
;
data want; set have;
if indexw(name_last,'AKA') > 1 then do;
name_last=substr(name_last,1,indexw(name_last,'AKA')-1);
end;
run;
Use SUBSTRN() instead of SUBSTR() .
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.