Rabidwolff's Alehouse
"Your place for fun and knowledge."
HOME | Quotes | SAS | C# | BEER



Basics
FORMATS
INFORMATS
DATETIME
ATTRIB
LENGTH
FORMAT
INFORMAT
LABEL
JOINS
OPERATORS

Statements
RETAIN
FIRST.
LAST.

Procedures
PROC SORT
PROC COPY
PROC CPORT
IF ELSE
PROC REPORT

Functions
CAT
CATS
CATT
CATX

CDISC
Random Q & A

CDISC
CDISC Info

Coded Tools
XML Output
Examples

IF ELSE Statement

IF (Subsetting Reading In Data)

When an IF statment is used in a DATA STEP with only an expression (not also using a THEN statement), then it will filter data. This is used to subset or allow only processing of the data that meets the IF statment's condition.



INPUT_TEST:
IDNAME
1Allan
2Joe
3Charley
4Mike
5Edward
6Frank
  OUTPUT_TEST:
IDNAME
1Allan
3Charley
5Edward

IF THEN ELSE Statement

The IF THEN ELSE statement is used to evaluate expressions and if found true, to process a certain block of code. The optional ELSE IF statement allows for multiple condition blocks while a final optional ELSE statement allows a default code block if all previous conditions failed.



INPUT_TEST:
IDNAMECondition
1AllanNone
2JoeNone
3CharleyNone
4MikeNone
5EdwardNone
6FrankNone
  OUTPUT_TEST:
IDNAMECondition
1AllanDefaulted Condition
2JoeCondition 2 Met
3CharleyCondition 3 Met
4MikeCondition 4 Met
5EdwardDefaulted Condition
6FrankDefaulted Condition

Notes
  • The first 'if' statement is not connected to the rest of the 'if-else' chain. Due to this, the defaulted 'else' statement matches its expreesion and the Condition is overwritten where ID = 1.
  • When only one statement is used within an 'if' statement block then it does not need to be surrounded by 'do;'-'end;' statements.
  • Using 'if' and 'if-else' statements are always mutually exclusive, while seperate 'if' statements are completely independant.
  • Using a final 'else' only statement will pass for all conditions not met int he previous included 'if'/'if else' expressions.

Rabidwolff Industries | Establisted: 10/15/2011 | Version: 4 8/4/2012 | Page Last Generatated: 9/25/2021 3:28:56 PM