I have a lookup table of product names (around 200)
For example,
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...
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?
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.
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.