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

Hi dear all.

I have a basic function and I can't find what i'm looking for...

the below code works:

 

data have;
re="all";
ro="hello";
ra=catx('',ro,re);
texto='blablabla hello all , people';
	if indexw(texto,ra)>0 then do;
	bi="wee";
	end;
	run;

and this one not ... ( because there is a comma after 'all' in texto:

data have;
re="all";
ro="hello";
ra=catx('',ro,re);
texto='blablabla hello all, people';
	if indexw(texto,ra)>0 then do;
	bi="wee";
	end;
	run;



how to fix that, to make the index or indexw find the word even if there is a comma, period etc after or before the searched word ( or series of words' like ro re... ?


Thanks for the response.

Sincerely.

1 ACCEPTED SOLUTION

Accepted Solutions
anushreebiotech
Obsidian | Level 7

Hi,

 

You can use Trim function.

 

data have;
re="all";
ro="hello";
ra=catx('',ro,re);
texto='blablabla hello all, people';
if index(texto,(trim(ra)))>0 then do;
bi="wee";
end;
run;

 

Regards,

Anushree

View solution in original post

4 REPLIES 4
anushreebiotech
Obsidian | Level 7

Hi,

 

You can use Trim function.

 

data have;
re="all";
ro="hello";
ra=catx('',ro,re);
texto='blablabla hello all, people';
if index(texto,(trim(ra)))>0 then do;
bi="wee";
end;
run;

 

Regards,

Anushree

Riteshdell
Quartz | Level 8

In your second code of texto attribute of value, space is removed  after "ALL".

Thats why you are not getting result.

as per First code, Space is there after ALL.

add space and then run.

SIgnificatif
Quartz | Level 8

The mentioned solution is working, I've also used strip and it worked too...

thanx 🙂

ballardw
Super User

INDEXW has an options parameter to contain delimiters. The default delimiter is blank.

Add additional delimiters as a string literal or variable containing desired delimiters after the search string.

Note that you do want to include a blank or that would stop being a delimiter.

 

if indexw(texto,ra, " ,.!?/()&%" )>0 then do

 

 

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
  • 1362 views
  • 0 likes
  • 4 in conversation