SAS - IF Statement


Advertisements


An IF statement consists of a boolean expression followed by SAS statements.

Syntax

The basic syntax for creating an if statement in SAS is −

IF (condition );

If the condition evaluates to be true, then the respective observation is processed.

Flow Diagram

SAS if statement

Example

DATA EMPDAT;
INPUT   EMPID ENAME $ SALARY DEPT $ DOJ DATE9.;
LABEL ID = 'Employee ID';
FORMAT DOJ DATE9.;
DATALINES;
1 Rick 623.3 IT 02APR2001
2 Dan 515.2 OPS 11JUL2012
3 Mike 611.5 IT 21OCT2000
4 Ryan 729.1 HR 30JUL2012
5 Gary 843.2 FIN 06AUG2000
6 Tusar 578.6 IT 01MAR2009
7 Pranab 632.8 OPS 16AUG1998
8 Rasmi 722.5 FIN 13SEP2014
;
Data EMPDAT1;
Set EMPDAT;
IF SALARY > 650;
PROC PRINT DATA = EMPDAT1;
run; 

When the above code is executed, it produces the following result −

sas_if_result.JPG
sas_decision_making.htm

Advertisements