Previous Page | Next Page

SAS Component Language Dictionary

SELECT



Executes one of several statements or groups of statements
Category: Control Flow
Comparisons: SAS Statement with limitations in SCL

Syntax
Differences in SELECT Statement Execution
Example

Syntax

SELECT<(select-expression)>;
WHEN-1 <(when-expression)>statement(s);
<. . .WHEN-n <(when-expression)>statement(s);>
<OTHERWISE <statement(s)>;>
END;

select-expression

is an expression that evaluates to a single value. This argument is optional. If used, select-expression must be in parentheses.

Type: Character

when-expression

is a constant or an expression that evaluates to a single value.

Type: Character

statement(s)

are one or more executable SAS statements, including DO, SELECT, and null statements. When used in a WHEN statement, a null statement causes SAS to recognize a condition as true without taking further action. In OTHERWISE statements, null statements prevent SAS from issuing an error message when all WHEN conditions are false.

Type: Character


Differences in SELECT Statement Execution

For SELECT groups in SCL, WHEN statements of the form WHEN(a1, a2, a3) are not supported. However, the following forms are supported:

OTHERWISE is an optional statement. If OTHERWISE is omitted, and if no WHEN conditions are met, the program halts.

Each WHEN statement implies a DO group of all statements until the next WHEN or OTHERWISE statement. Therefore, the following program is valid:

select(x);
   when(1)  call display('a');
     ...optionally, more SCL statements...
   when(2)  call display('b');
     ...optionally, more SCL statements...
   otherwise call display('bad');
     ...optionally, more SCL statements...
end;

For details about the SELECT statement in the Base SAS language, see SAS Language Reference: Dictionary.


Example

This example shows how to use expressions with the SELECT statement:

select;
    when(x=1)  put 'one';
    when(2<x<5) put 'between two and five';
    when(x>5 or x<0) put 'other';
end;

Previous Page | Next Page | Top of Page