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!
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.