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

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Aidan
Quartz | Level 8

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

View solution in original post

6 REPLIES 6
Ksharp
Super User

data want;

 set have;

 if prxmatch('/xx|yy|zz|aa|bb|cc/',long_string) then found=1;

 else found=0;

run;

PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
Ksharp
Super User

data want;

 set have;

 if prxmatch('/xx|yy|zz|aa|bb|cc/',long_string) then found=1;

 else found=0;

run;

Ksharp
Super User

data want;

 set have;

 if prxmatch('/xx|yy|zz|aa|bb|cc/',long_string) then found=1;

 else found=0;

run;

Aidan
Quartz | Level 8

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

Aidan
Quartz | Level 8
got it working using this thanks anyway 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 896 views
  • 1 like
  • 3 in conversation