Hello everybody,
I wanted to ask if I can combine in one command both an "and" and multiple "or" statements - or the opposite. For example something like:
if var1=5 and (var2=2 or var2=4 or var2=5) then var3=20;
thank you very much,
Dimitrios
Of course, you can. Why not?
For example :
data _NULL_;
set sashelp.class;
if Sex='M' AND (Age > 20 OR Height > 70 OR Weight > 100) then put 'HIT';
else put 'No HIT';
run;
Mind De Morgan's laws when combining AND's , OR's and NOT.
Koen
Of course, you can. Why not?
For example :
data _NULL_;
set sashelp.class;
if Sex='M' AND (Age > 20 OR Height > 70 OR Weight > 100) then put 'HIT';
else put 'No HIT';
run;
Mind De Morgan's laws when combining AND's , OR's and NOT.
Koen
An alternative that might make this more readable:
if var1=5 and var2 in (2, 4, 5) then var3=20;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.