Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Formatting Variables and Values

Creating Formats

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.

for14.gif (5615 bytes)

Figure 24.14: Program Editor


Choose Run:Submit.


[menu]
Figure 24.15: Run Menu


Select YR_MAJOR.

for16.gif (11108 bytes)

Figure 24.16: YR_MAJOR Selected


Choose Edit:Formats:Other.


This displays the Format Dialog.

for17.gif (5571 bytes)

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.

for18.gif (5630 bytes)

Figure 24.18: YEARFMT Entered


Click OK to close the Format dialog.


Now YEARFMT is used to display the values of YR_MAJOR.

for19.gif (11036 bytes)

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.

for20.gif (7633 bytes)

Figure 24.20: Box Plot Variables Dialog


Click the OK button to create the box plot.

for21.gif (8731 bytes)

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.

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.