Unlike IF-THEN logic, which simply moves to the next observation if no condition is true, the SELECT statement in SAS will trigger a fatal error and stop the Data Step if it encounters a value that matches none of the WHEN clauses; therefore, you should always include an OTHERWISE statement (even if it is just a null statement like 'otherwise;') to handle unexpected values safely.
Type : CREATION_INTERNE
The examples use data from the SASHELP library (sashelp.shoes).
| 1 | DATA shoes; |
| 2 | SET sashelp.shoes(where=(Region='Canada' or Region='Pacific' or Region='Asia')); |
| 3 | keep Region Sales Product; |
| 4 | select(Region); |
| 5 | when('Canada') sales = sales * .10; |
| 6 | when('Pacific') sales = sales * .09; |
| 7 | when('Asia') sales = sales * .07; |
| 8 | END; |
| 9 | RUN; |
| 10 | PROC PRINT DATA=shoes; RUN; |