Hi,
Please help me on this. I'm writing a SAS code to select from group of variables.
Sample data:
Store number Store list
----------------- ------------
2 (2,4,5)
3 (33,44,9)
10 (3,10,2)
35 (9,2,4)
12 (35,12,25)
I'm expecting a report as below:
2
10
10
i.e. 'Store number' present from 'store list'... 2 is present from (2,4,5) list and 10 is present from (3,10,2) and 12 from (35,12,25).
Are these values in the same dataset? Different data sets? Is the "list" a single value as shown complete with commas and parentheses?
Both of them are present in the same dataset. yes, the list always in the same format with commas and parentheses like (2,3,4)
You can use FINDW or INDEXW, make sure to specify the delimiters in the third paramter.
You can't use FIND() or INDEX() because 2 will be found in 12, 22, 23, etc.
data want;
set have;
x=put(find, 8. -l);
if findw(string, trim(compress(x)), '(),')>0 then output;
run;
Thanks much.. It worked perfectly!
alternatively with do until
data want ;
set have;
i=0;
do until(scan(compress(Store_list,'()'),i,',') eq '') ;
i+1;
if compress(Store_number) eq scan(compress(Store_list,'()'),i,',') then output;
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.