Hi there
What I want to do is search for a string within a large text string.
So I will have around 100 products for instance.
What I need to know is if any of these 100 products appear in a larger text string (which will have a lot of junk text but will have the product name in places) stored in a different table.
I am thinking I will need some sort of loop but not certain if their is an easier way to achieve this.
Any suggestions or helpful link or examples would be fantastic.
Thanks
Aidan
Hi there
I dont think this will work for me, thanks all the same.
I found something below;
data _NULL_;
set &_INPUT1 end=last;
if _n_=1 then call execute('data want; set &_INPUT2; length wordsfound $50;');
call execute('if findw(LOG_NOTES,"'||strip(word)||'") >0 then wordsfound=catx(",",wordsfound,"'||strip(word)||'");');
if last then call execute('run;');
run;
This seems to work to some extent but it wont return any value for wordsfound, just set to null
data want;
set have;
if prxmatch('/xx|yy|zz|aa|bb|cc/',long_string) then found=1;
else found=0;
run;
This part of the code from @Ksharp
'/xx|yy|zz|aa|bb|cc/'
can be created easily by PROC SQL. So assume the 100 product names are in a SAS data set named PRODUCT_NAMES (one product name on each row)
Then
proc sql noprint;
select distinct name into :names separated by '|' from product_names;
quit;
%let names1=%str(%')/&names/%str(%');
data want;
set have;
if prxmatch(%unquote(&names1),long_string) then found=1;
else found=0;
run;
data want;
set have;
if prxmatch('/xx|yy|zz|aa|bb|cc/',long_string) then found=1;
else found=0;
run;
data want;
set have;
if prxmatch('/xx|yy|zz|aa|bb|cc/',long_string) then found=1;
else found=0;
run;
Hi there
I dont think this will work for me, thanks all the same.
I found something below;
data _NULL_;
set &_INPUT1 end=last;
if _n_=1 then call execute('data want; set &_INPUT2; length wordsfound $50;');
call execute('if findw(LOG_NOTES,"'||strip(word)||'") >0 then wordsfound=catx(",",wordsfound,"'||strip(word)||'");');
if last then call execute('run;');
run;
This seems to work to some extent but it wont return any value for wordsfound, just set to null
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.