FORMAT Procedure

VALUE Statement

Creates a format that specifies character strings to use to print variable values.
See: SAS Formats and Informats: Reference for documentation about SAS formats.
Creating a Format for Character Values

Writing a Format for Dates Using a Standard SAS Format

Writing Ranges for Character Strings

Syntax

VALUE <$>name <(format-option(s))>

Summary of Optional Arguments

specifies the default length of the format.
specifies a fuzz factor for matching values to a range.
specifies a maximum length for the format.
specifies a minimum length for the format.
enables the assignment of multiple labels or external values to internal values.
specifies the assignment of a value or a range of values to a formatted value.
Control the attributes of the format
stores values or ranges in the order in which you define them.

Required Argument

name
names the format that you are creating. If you created a function using the FCMP procedure to use as a format, name is the function name without parenthesis.
Restrictions:The name of a user-defined format cannot be the same as the name of a format that is supplied by SAS.

Format names cannot end in a number.

Requirement:The name must be a valid SAS name. A numeric format name can be up to 32 characters in length. A character format name can be up to 31 characters in length. If you are creating a character format, then use a dollar sign ($) as the first character.
Interaction:The maximum length of a format name is controlled by the VALIDFMTNAME= system option. See SAS System Options: Reference for details.
Tips:Refer to the format later by using the name followed by a period. However, do not use a period after the format name in the VALUE statement.

Optional Arguments

DEFAULT=length
specifies the default length of the format. The value for DEFAULT= becomes the length of the format if you do not give a specific length when you associate the format with a variable.
The default length of a format is the length of the longest formatted value.
Tip:As a best practice, if you specify an existing format in a value-range set, always specify the DEFAULT= option.
FUZZ=fuzz-factor
specifies a fuzz factor for matching values to a range. If a number does not match or fall in a range exactly but comes within fuzz-factor, then the format considers it a match. For example, the following VALUE statement creates the LEVELS. format, which uses a fuzz factor of .2:
value levels (fuzz=.2) 1='A'
                       2='B'
                       3='C';
FUZZ=.2 means that if a variable value falls within .2 of a value on either end of the range, then the format uses the corresponding formatted value to print the variable value. So the LEVELS. format formats the value 2.1 as B.
If a variable value matches one value or range without the fuzz factor, and also matches another value or range with the fuzz factor, then the format assigns the variable value to the value or range that it matched without the fuzz factor.
Default:1E−12 for numeric formats and 0 for character formats.
Tip:Specify FUZZ=0 to save storage space when you use the VALUE statement to create numeric formats.
MAX=length
specifies a maximum length for the format. When you associate the format with a variable, you cannot specify a width greater than the MAX= value.
Default:40
Range:1–40
MIN=length
specifies a minimum length for the format.
Default:1
Range:1–40
MULTILABEL
enables the assignment of multiple labels or external values to internal values. The following VALUE statements show the two uses of the MULTILABEL option. The first VALUE statement assigns multiple labels to a single internal value. Multiple labels can also be assigned to a single range of internal values. The second VALUE statement assigns labels to overlapping ranges of internal values. The MULTILABEL option allows the assignment of multiple labels to the overlapped internal values.
value one (multilabel)
    1='ONE'
    1='UNO'
    1='UN';

  value agefmt (multilabel)
    15-29='below 30 years'
    30-50='between 30 and 50'
    51-high='over 50 years'
    15-19='15 to 19'
    20-25='20 to 25'
    25-39='25 to 39'
    40-55='40 to 55'
    56-high='56 and above';
Only multilabel-enabled procedures such as PROC MEANS, PROC SUMMARY, and PROC TABULATE can use multiple labels. All other procedures and the DATA step recognize only the primary label.
The primary label for a given entry is the external value that is assigned to the first internal value or range of internal values that matches or contains the entry when all internal values are ordered sequentially. Here is an example:
  • In the first VALUE statement, the primary label for 1 is ONE because ONE is the first external value that is assigned to 1. The secondary labels for 1 are UNO and UN.
  • In the second VALUE statement, the primary label for 33 is 25 to 39 because the range 25–39 is sequentially the first range of internal values that contains 33. The secondary label for 33 is between 30 and 50 because the range 30–50 occurs in sequence after the range 25–39.
Restriction:The maximum number of labels that can be created for a single format mat is 255.
NOTSORTED
stores values or ranges in the order in which you define them. If you do not specify NOTSORTED, then values or ranges are stored in sorted order by default, and SAS uses a binary searching algorithm to locate the range that a particular value falls into. If you specify NOTSORTED, then SAS searches each range in the order in which you define them until a match is found.
Use NOTSORTED if one of the following is true:
  • You know the likelihood of certain ranges occurring, and you want your format to search those ranges first to save processing time.
  • You want to preserve the order that you define ranges when you print a description of the format using the FMTLIB option.
  • You want to preserve the order that you define ranges when you use the ORDER=DATA option and the PRELOADFMT option to analyze class variables in PROC MEANS, PROC SUMMARY, or PROC TABULATE.
Do not use NOTSORTED if the distribution of values is uniform or unknown, or if the number of values is relatively small. The binary searching algorithm that SAS uses when NOTSORTED is not specified optimizes the performance of the search under these conditions.
SAS automatically sets the NOTSORTED option when you use the CPORT and the CIMPORT procedures to transport formats between operating environments with different standard collating sequences. This automatic setting of NOTSORTED can occur when you transport formats between ASCII and EBCDIC operating environments. If this situation is undesirable, then do the following:
  • Use the CNTLOUT= option in the PROC FORMAT statement to create an output control data set.
  • Use the CPORT procedure to create a transport file for the control data set.
  • Use the CIMPORT procedure in the target operating environment to import the transport file.
  • In the target operating environment, use PROC FORMAT with the CNTLIN= option to build the formats from the imported control data set.
value-range-set(s)
specifies the assignment of a value or a range of values to a formatted value. The value-range-set(s) have the following form:
value-or-range-1<..., value-or-range-n>= | [existing-format]
The variable values on the left side of the equal sign prints as the character string on the right side of the equal sign.
value-or-range
For details about how to specify value-or-range, see Specifying Values or Ranges.
formatted-value
specifies a character string that becomes the printed value of the variable value that appears on the left side of the equal sign. Formatted values are always character strings, regardless of whether you are creating a character or numeric format.
Formatted values can be up to 32,767 characters. For hexadecimal literals, you can use up to 32,767 typed characters, or up to 16,382 represented characters at 2 hexadecimal characters per represented character. Some procedures, however, use only the first 8 or 16 characters of a formatted value.
Requirements:You must enclose a formatted value in single or double quotation marks. The following example shows a formatted value that is enclosed in double quotation marks:
value $ score    
   'M'="Male"
   'F'="Female";

If a formatted value contains a single quotation mark, then enclose the value in double quotation marks:

value sect 
   1="Smith's class" 
   2="Leung's class";

Tip:Formatting numeric variables does not preclude the use of those variables in arithmetic operations. SAS uses stored values for arithmetic operations.
existing-format
specifies a format that is supplied by SAS or an existing user-defined format. The format that you are creating uses the existing format to convert the raw data that is a match for value-or-range on the left side of the equal sign.
Using an existing format can be thought of as nesting formats. A nested level of one means that if you are creating the format A with the format B as a formatted value, then the procedure has to use only one existing format to create A.
Requirement:If you use an existing format, then enclose the format name in square brackets (for example, [date9.]) or with parentheses and vertical bars (for example, (|date9.|)). Do not enclose the name of the existing format in single quotation marks.
Tips:Avoid nesting formats more than one level. The resource requirements can increase dramatically with each additional level.

As a best practice, if you specify an existing format in value-range-set, always specify a default value by using the DEFAULT= option.

Examples

Example 1: Create a Format to Print Postal Codes for Selected States

The $STATE. character format prints the postal code for selected states:
value $state 'Delaware'='DE'
              Florida'='FL'
              'Ohio'='OH';
The variable value Delaware prints as DE, the variable value Florida prints as FL, and the variable value Ohio prints as OH. Note that the $STATE. format begins with a dollar sign.
Note: Range specifications are case sensitive. In the $STATE. format above, the value OHIO would not match any of the specified ranges. If you are not certain what case the data values are in, then one solution is to use the UPCASE function on the data values and specify all uppercase characters for the ranges.

Example 2: Write Numeric Values as Character Values

The numeric format ANSWER.writes the values 1 and 2 as yes and no:
value answer 1='yes'
             2='no';

Example 3: Specifying No Ranges

This VALUE statement creates a format-name format that has no ranges:
value format-name;
Using this format has the effect of applying the default SAS format to the values.