Conditional Execution
It is rare that data processing is so simple that you want to execute every statement in the Data step for every execution. How do you only execute certain statements some of the time?
The most common way is with the IF-THEN statement. It says, "if this is true, then do that."
IF-THEN/ELSE statement (data step only)
|
Common examples include:
IF Score > 10 then Range='Clinical';
IF Gender = 'F' then Nfemale=Nfemale+1;
IF State = 'VA' and City = 'Richmond' then Murders='High';
For more information see SL:R, Chapter 4 Rules of the SAS Language, SAS Expressions and see, in the same chapter, SAS Operands.
The ELSE statement is optional but if it appears it must follow the IF statement.
Potential pitfall: Note that there is a semicolon at the end of the THEN clause at the end of the IF statement. A semicolon separates the IF statement and the ELSE statement.