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

I have a lookup table of product names (around 200)

 

For example,

  • BARKAT
  • CALOGEN
  • CALSHAKE
  • etc.

and I would like to search each of these products through all of my observations. 

I am not sure how to go about this as I am still new to SAS...

I need to do some sort of a scan as the product names do not exactly match up.

 

For example, when I search for these names in the productname variable, I would like to flag things like...

 

  • Barkat brown rice
  • Calogen extra
  • Calogen extra shots
  • Calshake
  • etc.

 

I made a cntlin list of the product names, and tried to use indexw/findw, but these seem to require individual words. My list is up to 200, so a manual search is not an option. I wonder if there is a way to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This isn't the best topic to be starting to learn with if your new to SAS.  

As for how to do it, there are a few ways, the way I would go with (and you have not provided any test data in the form of datasteps so this is only an example) - assumes listofwords contains the words, and have contains one string variable called sentance:

data _null_;
  set listofwords end=last;
  if _n_=1 then call execute('data want; set have; length wordsfound $2000;');
  call execute('if findw(sentance,"'||strip(word)||'") >0 then wordsfound=catx(",",wordsfound,"'||strip(word)||'");');
  if last then call execute('run;');
run;

What this does is create the datastep code after this is executed, which has an if statement for each word in listofwords, with a catx() function call to add any words found to wordsfound variable.  

 

As mentioned this is advanced, not a good area for learning as the above probably doesn't make any sense to you.

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This isn't the best topic to be starting to learn with if your new to SAS.  

As for how to do it, there are a few ways, the way I would go with (and you have not provided any test data in the form of datasteps so this is only an example) - assumes listofwords contains the words, and have contains one string variable called sentance:

data _null_;
  set listofwords end=last;
  if _n_=1 then call execute('data want; set have; length wordsfound $2000;');
  call execute('if findw(sentance,"'||strip(word)||'") >0 then wordsfound=catx(",",wordsfound,"'||strip(word)||'");');
  if last then call execute('run;');
run;

What this does is create the datastep code after this is executed, which has an if statement for each word in listofwords, with a catx() function call to add any words found to wordsfound variable.  

 

As mentioned this is advanced, not a good area for learning as the above probably doesn't make any sense to you.

Dani08
Obsidian | Level 7
Thank you this absolutely worked, but as you say I will need to look into the code to understand it fully. Thank you for your time.

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
  • 2 replies
  • 814 views
  • 1 like
  • 2 in conversation