• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • HTML
    • JavaScript
    • jQuery
    • PHP
    • Python
    • SAS
    • Ruby
  • About
You are here: Home / SAS / SAS If Then Statements with Multiple Variables

SAS If Then Statements with Multiple Variables

April 22, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  SAS left() Function – Left Align Character Variables in Data Step
  • 2.  Get the Row Number in a SAS Data Step with _n_
  • 3.  Round Number to Nearest Integer in SAS
  • 4.  Get Substring from Right in SAS
  • 5.  Multiple Condition If Statements in SAS Macro Language
  • 6.  Identifying Duplicates in SAS with PROC SORT dupout Option
  • 7.  Get Last Observation of SAS Dataset with end=
  • 8.  catx SAS – Concatenate String Variables with Delimiter in SAS Data Step
  • 9.  SAS include – Execute Code from Other Files in SAS with %include
  • 10.  SAS select when – Evaluating Character Values for Conditional Processing

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy