Recoding using Formats
Back to recoding. In the examples of recoding so far, you built a new variable with the recoded value. You can achieve the desired grouping by printing the original continuous values of SCORE with a custom format you build. Only the printed value of SCORE is changed, the stored value remains the same.
This is done in two steps: 1 step to build the format and 1 step to use the format. The code:
PROC FORMAT; VALUE SCORE 0-64 ='F' 65-69 ='D' 70-79 ='C' 80-89 ='B' 90-HIGH='A'; PROC PRINT DATA=GRADES; FORMAT SCORE SCORE.; TITLE 'Example 3';
The Proc Print output appears below.
Example 3 OBS SCORE ID GRADE 1 F 1 F 2 D 2 D 3 C 3 C 4 C 4 C 5 B 5 B 6 A 6 A 7 A 7 A 8 A 8 A 9 A 9 A
From the output above, the printed result is the same using GRADE - a character variable created with IF-THEN/ELSE structures - and SCORE, a numeric variable with integer values printed with a custom format. That's the beauty of formats, without rebuilding a dataset you can print any variable any way you want to.
The FORMAT statement in the PROC PRINT step associates the variable SCORE with the format SCORE. . (Don't forget the period).