Previous PageNext Page

Example 4 creating a new variable using formats
Here is another way to recode an existing variable into a small number of categories.

PROC FORMAT;
VALUE SCORE  0-<65  ='F'
            65-<70  ='D'
            70-<80  ='C'
            80-<90  ='B'
            90-HIGH ='A';

Data Grades;
     ID = _N_;
     Input Score;
     GRADE = Put (Score, Score.);
Datalines;
55
65
74
76
88
92
94
96
98
0
-1
101
82.1
89.1
.
;
PROC PRINT DATA=GRADES;
     TITLE 'Example 4';
     ID ID;
run;

Note that the definition of the format must precede its use; The PROC FORMAT step must run before the DATA step. "Before the DATA step" could mean in a previous SAS session when the format was saved for later use.

Previous PageTable Of ContentsNext Page