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.
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
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
Thanks! It worked 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.