Example 2: The SELECT-WHEN structure
Another - more efficient - way to code statements to execute conditionally is with the SELECT-WHEN structure. The following code achieves results identical to that above using the IF-THEN/ELSE structure.
Data Grades; Input Score; ID = _N_; SELECT; WHEN ( 0 LE Score LT 65) Grade='F'; WHEN (65 LE SCORE LT 70) Grade='D'; WHEN (70 LE SCORE LT 80) Grade='C'; WHEN (80 LE SCORE LT 90) Grade='B'; WHEN ( SCORE GE 90) Grade='A'; OTHERWISE Grade=.; END; Datalines;
Notice that the SELECT block is ended with the END statement.
SELECT-WHEN structures (data step only)
|
For more information see SL:R, Chapter 9 SAS Language Statements