BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ElisaC
Calcite | Level 5

I am using SAS 9.4. I want to subset my dataset to include only records containing certain values in at least one variable of a set of variables. I have 10 variables (var1-var10) containing values like A100 or B250. There are hundreds of different possible values and I only need records containing certain values.

I tried this code:

 

data abc.subset;
  set abc.dataset;
  array vars var1-var10;
  if 'A100' in vars ;
run;

 

 and it works with just one value (A100), but when I add more values:

data abc.subset;
  set abc.dataset;
  array vars var1-var10;
  if ('A100' or 'B250) in vars ;
run;

then the log returns a note saying: Invalid numeric data. How can I do this?

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
smantha
Lapis Lazuli | Level 10
data abc.subset;
  set abc.dataset;
  array vars var1-var10;
  if 'A100' in vars or 'B250' in vars ;
run;
'A100' or 'B250' returns 1 as both are non missing and then converts them into a character for comparison

View solution in original post

2 REPLIES 2
smantha
Lapis Lazuli | Level 10
data abc.subset;
  set abc.dataset;
  array vars var1-var10;
  if 'A100' in vars or 'B250' in vars ;
run;
'A100' or 'B250' returns 1 as both are non missing and then converts them into a character for comparison

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1674 views
  • 2 likes
  • 2 in conversation