Formatting Variables and Values |
Although there are many formats available in the SAS System, occasionally you will want to create your own. To do this, use the FORMAT procedure.
For example, suppose you want to consider certain groupings of baseball players based on the length of their careers. You can combine the values of YR_MAJOR into four groups, as follows.
Enter PROC FORMAT statements in the Program Editor. |
Figure 24.14: Program Editor
Choose Run:Submit. |
Select YR_MAJOR. |
Figure 24.16: YR_MAJOR Selected
Choose Edit:Formats:Other. |
This displays the Format Dialog.
Figure 24.17: Format Dialog
Enter YEARFMT in the Name field. |
Enter 12 in the w field, then press the Return key. |
Now the example in the upper right of the dialog shows a value formatted with YEARFMT.
Figure 24.18: YEARFMT Entered
Click OK to close the Format dialog |
Now YEARFMT is used to display the values of YR_MAJOR.
Figure 24.19: YEARFMT Assigned
By default, the new format is used to display values wherever you use YR_MAJOR. Formats are not used in calculations except for nominal variables in model effects or for group variables. In these cases, the format is used to determine the groups. You can see this use of formats by creating a box plot.
Deselect YR_MAJOR in the data window. |
Choose Analyze:Box Plot/Mosaic Plot ( Y ). |
This displays the box plot variables dialog.
Assign YR_MAJOR the X role and CR_HITS the Y role. |
Figure 24.20: Box Plot Variables Dialog
Click the OK button to create the box plot. |
Figure 24.21: Box Plot of CR_HITS by YR_MAJOR
Since YEARFMT defines four formatted values, there are four boxes in the box plot. One of the boxes has no whiskers because it represents only two observations. Pete Rose and Tony Perez, ballplayers of exceptional hitting ability and longevity, are in a class by themselves.
To learn more about SAS formats, refer to SAS Language Reference: Dictionary. To learn more about creating your own formats with PROC FORMAT, refer to the SAS Procedures Guide.
Related Reading |
Box Plots, Chapter 33. |
Copyright © 2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.