BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
elli444
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Use SUBSTRN() instead of SUBSTR() .

View solution in original post

4 REPLIES 4
ErikLund_Jensen
Rhodochrosite | Level 12

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?

elli444
Calcite | Level 5

We'd prefer the last name left unchanged.

ErikLund_Jensen
Rhodochrosite | Level 12

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;

 

 

ln.gif

 

 

 

Ksharp
Super User

Use SUBSTRN() instead of SUBSTR() .

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2215 views
  • 0 likes
  • 3 in conversation