I would like to subset my dataset to include only records where one or more of a set of variable meet a certain value.
My code looks like:
data work.test2
data work.test
if VAR1 | VAR 2 | VAR3 ... | VAR 30 = 'VALUE';
run;
How do I condense that to either VAR1-VAR30 = ' VALUE' or VARn = 'VALUE'? Using (keep=VAR1-VAR30) does not seem applicable in this case.
Thank you
Your posted code might be valid syntax, but it does not do what you claim to want.
There is special syntax for using IN with an array that could help.
data work.test2 ;
set data work.test;
array vars var1-var30;
if 'VALUE' in vars ;
run;
Or you could use the WHICHC() function. That will actually return which variable number was the first one found to have the value. You don't need an ARRAY for that. A value of 0 (which SAS will treat as FALSE when evaluating as boolean) will indicate that is was not found.
data work.test2 ;
set data work.test;
if whichc('VALUE',of var1-var30);
run;
Your posted code might be valid syntax, but it does not do what you claim to want.
There is special syntax for using IN with an array that could help.
data work.test2 ;
set data work.test;
array vars var1-var30;
if 'VALUE' in vars ;
run;
Or you could use the WHICHC() function. That will actually return which variable number was the first one found to have the value. You don't need an ARRAY for that. A value of 0 (which SAS will treat as FALSE when evaluating as boolean) will indicate that is was not found.
data work.test2 ;
set data work.test;
if whichc('VALUE',of var1-var30);
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.