☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 05-03-2022 01:57 PM
(3898 views)
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
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
....... strangely enough my "question code" worked as well....!!!! thank you for the reply though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
An alternative that might make this more readable:
if var1=5 and var2 in (2, 4, 5) then var3=20;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you