SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Dim13
Obsidian | Level 7

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
sbxkoenk
SAS Super FREQ

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

View solution in original post

4 REPLIES 4
sbxkoenk
SAS Super FREQ

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

Dim13
Obsidian | Level 7
....... strangely enough my "question code" worked as well....!!!! thank you for the reply though.
Astounding
PROC Star

An alternative that might make this more readable:

 

if var1=5 and var2 in (2, 4, 5) then var3=20;
Dim13
Obsidian | Level 7
thank you

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3899 views
  • 4 likes
  • 3 in conversation