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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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