Hi,
I have one variable I want to compare to 21 others. I only want IF the variable CONTROL NOT EQUALS variables CONTROL1 to CONTROL21. Anyone has a better, simpler way of doing it than this?
IF CONTROL NE CONTROL1 AND CONTROL NE CONTROL2 AND CONTROL NE CONTROL3 AND CONTROL NE CONTROL 4.................. AND CONTROL NE CONTROL 21;
Thank you for the help;
Ismael
Nice ... would just change > 0 to eq 0 since looking for observations where CONTROL is NOT EQUAL to any of CONTOL1-CONTROL5, yes/no?
You don't give many details. For instance is it a character to character check, then maybe:
where catx(',',of control1-control21) not contains xyz;
I.e. if the string in variable xyz does not appear in a concatenation of all the others.
You could also do arrays:
array control{21};
do I=1 to 21;
if xyz=control{I} then found=1;
end;
if found=0 then ...
You could generate the code from a data _null_ using call execute, you could create a macro etc.
Hi. Re ...
"For instance is it a character to character check, then maybe: where catx(',',of control1-control21) not contains xyz;"
The CAT functions can be used with both CHARACTER and NUMERIC variables, for example ...
data test;
input control control1-control5;
datalines;
1 1 2 3 4 5
2 9 9 9 9 9
5 9 9 9 9 5
9 1 2 9 9 9
8 1 1 1 1 1
;
data new;
set test;
if ^find(cat(of control1-control5), cat(control));
run;
works with no annoying messages in the LOG.
ps ... Searching for Variable Values with CAT Functions: An Alternative to Arrays and Loops
Hi ... try this ...
data test;
input control control1-control5;
datalines;
1 1 2 3 4 5
2 9 9 9 9 9
5 9 9 9 9 5
9 1 2 9 9 9
8 1 1 1 1 1
;
data new;
set test;
array x(5) control1-control5;
if control not in x;
run;
ps Learned about this use of an array from Ksharp a while back.
Mike,
Actually , I learned it from data _null_;
How about
if whichn(control, of control1-control21) > 0; /* if NUMERIC */
if whichc(control, of control1-control21) > 0; /* if CHARACTER */
PG
Nice ... would just change > 0 to eq 0 since looking for observations where CONTROL is NOT EQUAL to any of CONTOL1-CONTROL5, yes/no?
Right!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.