BookmarkSubscribeRSS Feed
bharani721
Calcite | Level 5

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

5 REPLIES 5
ballardw
Super User

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

bharani721
Calcite | Level 5

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)

Reeza
Super User

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;
bharani721
Calcite | Level 5

Thanks much.. It worked perfectly!

Jagadishkatam
Amethyst | Level 16

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 2717 views
  • 0 likes
  • 4 in conversation