When using IF statements,
considerable processing improvements can be made by using the ELSE,
ELSE IF, and / or SELECT statements. These statements are widely used
and are well documented in the SAS Language manual, but it is
worthwhile considering how these statements are combined before
reverting to a single rule.
e.g.
IF CessReas=’E’ Then
If BusRes=’1’ Then
If District=’NI’ Then Output Dataset1;
Else Output Dataset2;
Else If BusRes=’2’ and District=’NI’ Then Output Dataset3;
Else Delete;
Else Delete;
is more efficient than
Else IF CessReas=’E’ and BusRes=’1’ and District = ’NI’ Then Output Dataset2;
Else IF CessReas=’E’ and BusRes=’1’ and District ne ’NI’ Then Output Dataset2;
Else IF CessReas=’E’ and BusRes=’2’ and District=’NI’ Then Output Dataset3;
Else Delete;
because the test
“CessReas” must be calculated 3 times, BusRes=1 twice, and
District ne ‘NI’ an additional time more than necessary.