You can easily create if then statements with multiple variables using the logical operators or and and in a SAS data step.
data k;
a = 3;
b = 5;
if a > 5 or b < 10 then put "success";
run;
/* Output */
success
If you are using the SAS Macro language, you can also easily define if then statements with multiple variables with or and and.
%macro process;
%let a = 3;
%let b = 5;
%if &a > 3 and &b < 10 %then %do;
%let c = 10;
%end;
%mend;
When working in SAS, we can use conditional expressions to control the flow of our code and data.
By using conditional expressions, such as if then statements, and logical operators, we can easily create code to deal with complicated data requirements.
When creating an if then statement in a SAS data step, many times we need to check multiple variables for different conditions.
Creating an if then statement with multiple variables in SAS is easy.
Depending on the conditions you want to set, you can use the logical operators or and and to design different conditional expressions for multiple variables.
Below is a simple example of how to create a multiple variable if then statement in SAS.
data k;
a = 3;
b = 5;
if a > 5 or b < 10 then put "success";
run;
/* Output */
success
Multiple Variable If Then Statements with SAS Macro Language
If you are using the SAS Macro Language, you can also easily define if then statements with multiple variables with or and and in the same way as in a SAS data step.
The SAS Macro Language is very powerful, and with conditional expressions, we can design code which allows us to handle complicated situations.
Again, depending on the conditions you want to set, you can use the logical operators or and and to design different conditional expressions for multiple macro variables.
Below is an example of how to create an if then statement for multiple variables in the SAS Macro Language.
%macro process;
%let a = 3;
%let b = 5;
%if &a > 3 and &b < 10 %then %do;
%let c = 10;
%end;
%mend;
Hopefully this article has been useful for you to learn how to create multiple variable if then statements in SAS.