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 🙂
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.