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
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
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.
Maybe some PRX?
FLAG=(prxmatch('/[DEX|HEX|RED|BET]/',VAR)>0);
Haikuo
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.
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
Yep- worked like magic! Thanks PGStats
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 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.