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

I want to search a variable in a very big data set for a list of specific substring.

I though index function would do the job, but index function can fit only one string to search for.

I var  on variable, and I want to search this variable for big number of small strings for example "DEX", HEX", "RED", "BET" and so on.

so I want any word in the search variable to be flagged if int has for example dexamethsone, hexagonal...etc

I was thinking this would work but it's not

if index(VAR, 'DEX', 'HEX', 'BET') >0 then flag=1

I don't  want to specify many if statements, because my st of search is big

Any ideas.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You might want to add a suffix to the pattern to improve efficiency and behaviour:

FLAG=(prxmatch('/DEX|HEX|RED|BET/io',VAR)>0);

The 'i' makes the match case insensitive and the 'o' instructs the function that the pattern should be compiled only once, otherwise, it is recompiled on every call.

PG

PG

View solution in original post

5 REPLIES 5
Astounding
PROC Star

There's no way I know of to search for all three at the same time.  To cut down the costs a bit, you can use:

if index(VAR, 'DEX') then flag=1;

else if index(VAR, 'HEX') then flag=1;

else if index(VAR, 'BET') then flag=1;

Good luck.

Haikuo
Onyx | Level 15

Maybe some PRX?

FLAG=(prxmatch('/[DEX|HEX|RED|BET]/',VAR)>0);

Haikuo

Altal
Calcite | Level 5

Thank you guys. That was really helpful.

Haikuo- thank you, I didn't think about the prxmatch function before. It worked; I minimally modified your code to work. Here is what worked for me...

FLAG=(prxmatch('/DEX|HEX|RED|BET/',VAR)>0);

You can add any substring and divide them by "|". This will save from putting multiple IF statements if looking for various substrings.

PGStats
Opal | Level 21

You might want to add a suffix to the pattern to improve efficiency and behaviour:

FLAG=(prxmatch('/DEX|HEX|RED|BET/io',VAR)>0);

The 'i' makes the match case insensitive and the 'o' instructs the function that the pattern should be compiled only once, otherwise, it is recompiled on every call.

PG

PG
Altal
Calcite | Level 5

Yep- worked like magic! Thanks PGStats

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 911 views
  • 6 likes
  • 4 in conversation