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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: