SELECT Statement
Executes one of several statements or groups of statements.
| Valid in: | DATA step |
| Categories: | CAS |
| Control | |
| Type: | Executable |
Syntax
Arguments
(select-expression)
specifies any SAS expression that evaluates to a single value.
| See | Evaluating the when-expression When a select-expression Is Included |
(when-expression)
specifies any SAS expression, including a compound expression. SELECT requires you to specify at least one when-expression.
| Tips | Separating multiple when-expressions with a comma is equivalent to separating them with the logical operator OR. |
| The way a when-expression is used depends on whether a select-expression is present. | |
| See | Evaluating the when-expression When a select-expression Is Not Included |
statement
can be any executable SAS statement, including DO, SELECT, and null statements. You must specify the statement argument.
Details
Using WHEN Statements in a SELECT Group
Evaluating the when-expression When a select-expression Is Included
Evaluating the when-expression When a select-expression Is Not Included
Processing Large Amounts of Data with %INCLUDE Files
Comparisons
Examples
Example 1: Using Statements
select (a); when (1) x=x*10; when (2); when (3,4,5) x=x*100; otherwise; end;
Example 2: Using DO Groups
select (payclass);
when ('monthly') amt=salary;
when ('hourly')
do;
amt=hrlywage*min(hrs,40);
if hrs>40 then put 'CHECK TIMECARD';
end; /* end of do */
otherwise put 'PROBLEM OBSERVATION';
end; /* end of select */Example 3: Using a Compound Expression
select;
when (mon in ('JUN', 'JUL', 'AUG')
and temp>70) put 'SUMMER ' mon=;
when (mon in ('MAR', 'APR', 'MAY'))
put 'SPRING ' mon=;
otherwise put 'FALL OR WINTER ' mon=;
end;Example 4: Making Comparisons for Equality
/* INCORRECT usage to select value of 2 */ select (x); /* evaluates T/F and compares for */ /* equality with x */ when (x=2) put 'two'; end; /* correct usage */ select(x); /* compares 2 to x for equality */ when (2) put 'two'; end; /* correct usage */ select; /* compares 2 to x for equality */ when (x=2) put 'two'; end;
Example 5: Processing Large Amounts of Data
data test (keep=ItemNumber);
set ItemList;
select;
%include NewItems;
%include OldItems;
otherwise put 'Item ' ItemNumber ' is not in the inventory.';
end;
run;