Published on :
Base SAS CREATION_INTERNE

IF-THEN-ELSE Conditional Structure

This code is also available in: Deutsch Español Français
This script illustrates the basic syntax of an IF-THEN-ELSE statement, which allows different blocks of code to be executed depending on the truthfulness of a specified condition. The placeholders '[Condition]' and '[Code goes here]' represent the conditional logic and the actions to be performed. This type of structure is fundamental for implementing logical decisions in data processing or macro programming.
Data Analysis

Type : CREATION_INTERNE


No data is explicitly processed, created, or imported in this example. The script presents a purely logical flow control structure without direct interaction with datasets or external files. The category 'CREATION_INTERNE' is used to indicate that the script does not depend on external data sources or SASHELP for its logical operation.

1 Code Block
DATA STEP
Explanation :
This code block demonstrates an 'IF-THEN-ELSE' conditional structure. The line 'if [Condition] then do;' introduces the condition to be evaluated. If the '[Condition]' is true, the code between 'do;' and the first 'end;' is executed. If the '[Condition]' is false, the code between 'else do;' and the second 'end;' is executed. The brackets indicate reserved locations for a valid SAS condition and the SAS code to be executed, respectively.
Copied!
1 * if _ then do;
2
3 IF [Condition] THEN DO;
4 [Code goes here];
5 END;
6 
7 ELSE DO;
8 [Code goes here];
9 END;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.