Previous Page | Next Page

Statements

IF-THEN/ELSE Statement



Executes a SAS statement for observations that meet specific conditions.
Valid: in a DATA step
Category: Control
Type: Executable

Syntax
Arguments
Details
Comparisons
Examples
See Also

Syntax

IF expression THEN statement;
<ELSE statement;>


Arguments

expression

is any SAS expression and is a required argument.

statement

can be any executable SAS statement or DO group.


Details

SAS evaluates the expression in an IF-THEN statement to produce a result that is either non-zero, zero, or missing. A non-zero and nonmissing result causes the expression to be true; a result of zero or missing causes the expression to be false.

If the conditions that are specified in the IF clause are met, the IF-THEN statement executes a SAS statement for observations that are read from a SAS data set, for records in an external file, or for computed values. An optional ELSE statement gives an alternative action if the THEN clause is not executed. The ELSE statement, if used, must immediately follow the IF-THEN statement.

Using IF-THEN statements without the ELSE statement causes SAS to evaluate all IF-THEN statements. Using IF-THEN statements with the ELSE statement causes SAS to execute IF-THEN statements until it encounters the first true statement. Subsequent IF-THEN statements are not evaluated.

Note:   For greater efficiency, construct your IF-THEN/ELSE statement with conditions of decreasing probability.   [cautionend]


Comparisons


Examples

These examples show different ways of specifying the IF-THEN/ELSE statement.


See Also

Statements:

DO Statement

IF Statement, Subsetting

SELECT Statement

Previous Page | Next Page | Top of Page