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() .
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.