Using a SELECT Statement to Recode a Variable - SAS Programming

An alternative to IF-THEN/ELSE coding is to use the SELECT statement.It is usually more efficient than IF-THEN/ELSE,especially if you are receding a variable into a large number of categories.There are various forms of the SELECT statement,but the one that does the trick here looks like the following:

Example

DATA RECODE;
SET GRADES;
SELECT;
WHEN (0 LE SCORE LT 65) GRADE*0;
WHEN (65 LE SCORE LT 70) GRA0E»1;
WHEN (70 LE SCORE LT 80) GRADE=2;
WHEN (80 LE SCORE LT 90) GRADE=3;
WHEN (SCORE GE 90) GRADE»4;
END;
RON?
PROC PRINT DATA*RECODE;
TITLE 'Example ';
RUN;

As you can see in this example,one or more WHEN statements can be placed between the SELECT and END statements.The statement
following the true WHEN condition is executed.Another useful feature of the SELECT statement is to follow your last WHEN statement with an OTHERWISE statement which is executed if none of the WHEN conditions is true.

There are other,more advanced,features of the SELECT statement which we do not cover here.The code above yields the same
output(except for the title) as Example 1.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics