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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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