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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1268 views
  • 1 like
  • 2 in conversation