Defining a Unique Format

The VALUE Statement

Use the VALUE statement to define a format for displaying one or more values.
Syntax, VALUE statement:
VALUE format-name
range1='label1'
range2='label2'
...more format-names...;
The following are true about format-name:
  • A format name must begin with a dollar sign ($) if the format applies to character data.
  • A format name must be a valid SAS name.
  • A format name cannot be the name of an existing SAS format.
  • A format name cannot end in a number.
  • A format name does not end in a period when specified in a VALUE statement.
  • A numeric format name can be up to 32 characters long.
  • A character format name can be up to 31 characters long.
Tip:If you are running a version of SAS prior to SASĀ®9, the format name must be a SAS name up to eight characters long and cannot end in a number.
Notice that the statement begins with the keyword VALUE and ends with a semicolon after all the labels have been defined. The following VALUE statements create the GENDER, AGEGROUP, and $COL formats to specify descriptive labels that are later assigned to the variables Sex, Age, and Color respectively:
proc format;
   value gender 	
              1 = 'Male'
              2 = 'Female';
   value agegroup  
             13 -< 20  = 'Teen'
             20 -< 65  = 'Adult'
             65 - HIGH = 'Senior';
   value $col 		
             'W' = 'Moon White'
             'B' = 'Sky Blue'
             'Y' = 'Sunburst Yellow'
             'G' = 'Rain Cloud Gray';
run;
The VALUE range specifies the following types of values:
  • a single value, such as 24 or 'S'
  • a range of numeric values, such as 0-1500
  • a range of character values enclosed in quotation marks, such as 'A'-'M'
  • a list of unique values separated by commas, such as 90,180,270 or 'B', 'D', 'F'. These values can be character values or numeric values, but not a combination of character and numeric values (because formats themselves are either character or numeric).
When the specified values are character values, they must be enclosed in quotation marks and must match the case of the variable's values. The format's name must also start with a dollar sign ($). For example, the VALUE statement below defines the $COL format, which displays the character values as text labels.
proc format lib=formtlib; 
   value $col 
         'W' = 'Moon White' 
         'B' = 'Sky Blue' 
         'Y' = 'Sunburst Yellow' 
         'G' = 'Rain Cloud Gray'; 
run;
When the specified values are numeric values, they are not enclosed in quotation marks, and the format's name should not begin with a dollar sign ($).

Specifying Value Ranges

You can specify a non-inclusive range of numeric values by using the less than symbol (<) to avoid any overlapping. In this example, the range of values from 0 to less than 13 is labeled as Child. The next range begins at 13, so the label Teenager would be assigned to the values 13 to 19.
proc format lib=formtlib; 
   value agefmt 
         0-<13='child' 
         13-<20='teenager' 
         20-<65='adult' 
         65-100='senior citizen'; 
run;
You can also use the keywords LOW and HIGH to specify the lower and upper limits of a variable's value range. The keyword LOW does not include missing numeric values. The keyword OTHER can be used to label missing values as well as any values that are not specifically addressed in a range.
proc format lib=formtlib; 
   value agefmt 
         low-<13='child' 
         13-<20='teenager' 
         20-<65='adult' 
         65-high='senior citizen' 
         other='unknown'; 
run;
Tip
If applied to a character format, the keyword LOW includes missing character values.
When specifying a label for displaying each range, remember to do the following:
  • Enclose the label in quotation marks.
  • Limit the label to 32,767 characters.
  • Use two single quotation marks if you want an apostrophe to appear in the label:
    000='employee''s jobtitle unknown';
To define several formats, you can use multiple VALUE statements in a single PROC FORMAT step. In this example, each VALUE statement defines a different format.
proc format;
   value gender 	
              1 = 'Male'
              2 = 'Female';
   value agegroup  
             13 -< 20  = 'Teen'
             20 -< 65  = 'Adult'
             65 - HIGH = 'Senior';
   value $col 		
             'W' = 'Moon White'
             'B' = 'Sky Blue'
             'Y' = 'Sunburst Yellow'
             'G' = 'Rain Cloud Gray';
run;
The SAS log prints notes informing you that the formats have been created.
Log 12.1 SAS Log
146  proc format lib=formtlib;
147      value gender    1 = 'Male'
148                      2 = 'Female';
NOTE: Format GENDER is already on the library FORMTLIB.FORMATS.
NOTE: Format GENDER has been output.
149      value agegroup  13 -< 20  = 'Teen'
150                      20 -< 65  = 'Adult'
151                      65 - HIGH = 'Senior';
NOTE: Format AGEGROUP is already on the library FORMTLIB.FORMATS.
NOTE: Format AGEGROUP has been output.
152      value $col      'W' = 'Moon White'
153                      'B' = 'Sky Blue'
154                      'Y' = 'Sunburst Yellow'
155                      'G' = 'Rain Cloud Gray';
NOTE: Format $COL is already on the library FORMTLIB.FORMATS.
NOTE: Format $COL has been output.
Last updated: August 23, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.74.3