05-18-2016 01:01 PM
I have a character string where that contains the names of various stores and I would like to filter the observations based on certain store values.
I tried substring function but it does not work all the time.
Below is an example of what I am looking for.
Desired Output file
Please let me know.
05-18-2016 01:52 PM
So you want to search but not for exact values?
I'm not sure what you need beyond the following:
data want; set have; where store_name in ('ABC STORE' 'COSTCO STORE' 'APPLE COMUTERS'); RUN;
05-18-2016 01:57 PM
yes, I am not searching for the exact values.
for eg: I need to find APPLE COMPUTERS in the desired output file with a filter of 'APPLE'.
I tested the where conditon but it did not work.
05-18-2016 02:29 PM
Thanks PG Stats!
Contians works but only with one value. It does not work in my test, where I checked for a list of values.
eg: where store_name in ('COSTCO') works.
but not ('COSTCO', 'APPLE', 'SAMS') - does not support I think.
05-18-2016 02:33 PM
Unfortunately all of the Contains/Find/Index functions all work with a single argument.
ie contains ("APPLE") or contains ("COMPUTERS") or contains("COSTCO")
Do you have your list in a dataset?
05-18-2016 03:25 PM
Here's an example using an array to loop through your words.
data have; input stores $32.; cards; ABC STORE APPLE COMPUTERS MICROSOFT CORPORATION COSTCO STORE WALMART SAMS CLUB ; run; data want; array lookup(2) $ _temporary_ ("COSTCO" "APPLE" ); set have; do i=1 to dim(lookup); if find(stores, trim(lookup(i)))>0 then output; end; run;
05-18-2016 09:22 PM
Reeza should use FINDW() .
Here is an alternative way .
data have; input stores $32.; cards; ABC STORE APPLE COMPUTERS MICROSOFT CORPORATION COSTCO STORE WALMART SAMS CLUB ; run; data want; set have; if prxmatch('/\b(COSTCO|APPLE|ABC)\b/i',stores); run;