DATA Step, Macro, Functions and more

Selecting from group

Reply
New Contributor
Posts: 3

Selecting from group

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).

Super User
Posts: 11,343

Re: Selecting from group

Posted in reply to bharani721

Are these values in the same dataset? Different data sets? Is the "list" a single value as shown complete with commas and parentheses?

New Contributor
Posts: 3

Re: Selecting from group

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)

Super User
Posts: 19,770

Re: Selecting from group

Posted in reply to bharani721

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;
New Contributor
Posts: 3

Re: Selecting from group

Thanks much.. It worked perfectly!

Trusted Advisor
Posts: 1,137

Re: Selecting from group

Posted in reply to bharani721

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;
Thanks,
Jag
Ask a Question
Discussion stats
  • 5 replies
  • 285 views
  • 0 likes
  • 4 in conversation