Hi Dear All.
I have this working code code :
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;
I would like to transorm the re variable to a list , so index could find the string if one of the values of the list 're' is found, here is an example
data have;
re="all|you"; /* will find if word 'all' or 'you' is found the text 'texto' below , text is delimited with | */
ro="hello";
ra=catx('',ro,re);
texto='blablabla hello all, people'; /* <= instead of word all , the text can contain the word you*/
if index(texto,(trim(ra)))>0 then do;
bi="wee";
end;
run;
Thank you for your response.
Using a array.
data have;
re="all|you";
ro="hello";
ra=catx('',ro,re);
texto='blablabla hello all, people'; /* <= instead of word all , the text can contain the word you*/
do i=1 to countw(re,'|');
temp=scan(re,i,'|');
if index(texto,(trim(temp)))>0 then do;
bi="wee";leave;
end;
end;
run;
proc print;run;
Hello,
data have;
re="\b(all|you)\b"; /* will find if word 'all' or 'you' is found the text 'texto' below , text is delimited with | */
ro="hello";
ra=catx('',ro,re);
texto='blablabla hello all, people'; /* <= instead of word all , the text can contain the word you*/
if prxmatch(cats("/",ra,"/"),texto) then do;
bi="wee";
end;
run;
Thank you for the response, but I would like to find the answer using sas code and not re.
(* sorry, since i forgot to mention that 😞 )
prxmatch is sas code but i understand you don't want to use regular expressions (why ?).
Here is a solution without regex. Note that it will match the string "hello young fellow" for instance.
data have;
re="all|you";
ro="hello";
texto='blablabla hello all, people';
do i=1 to countw(re,'|');
re2=scan(re,i,'|');
ra=catx('',ro,re2);
if index(texto, trim(ra)) then do;
bi="wee";
end;
end;
run;
Why not Regular Expressions? They are your best bet for this task.
I think that they are more expensive in terms of cpu usage.... unfortunately I did not find any article that compares re to sas functions ...
Using a array.
data have;
re="all|you";
ro="hello";
ra=catx('',ro,re);
texto='blablabla hello all, people'; /* <= instead of word all , the text can contain the word you*/
do i=1 to countw(re,'|');
temp=scan(re,i,'|');
if index(texto,(trim(temp)))>0 then do;
bi="wee";leave;
end;
end;
run;
proc print;run;
Thank you Dear Ksharp and All for your responses 🙂 it's ok now
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.