Syntax: FORMAT Procedure


Restriction: You cannot use a SELECT statement and an EXCLUDE statement within the same PROC FORMAT step.

Reminder: You can also use appropriate global statements with this procedure. See Global Statements on page 18 for a list.

See: FORMAT Procedure in the documentation for your operating environment.

PROC FORMAT < option(s) >;

  • EXCLUDE entry(s) ;

  • INVALUE <$> name <( informat-option(s) )>

    • value-range-set(s) ;

  • PICTURE name <( format-option(s) )>

    • value-range-set-1 <( picture-1-option(s) )>

    • < value-range-set-n <( picture-n-option(s) )>>;

  • SELECT entry(s) ;

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

    • value-range-set(s) ;

To do this

Use this statement

Exclude catalog entries from processing by the FMTLIB and CNTLOUT= options

EXCLUDE

Create an informat for reading and converting raw data values

INVALUE

Create a template for printing numbers

PICTURE

Select catalog entries from processing by the FMTLIB and CNTLOUT= options

SELECT

Create a format that specifies character strings to use to print variable values

VALUE

PROC FORMAT Statement

Reminder: You can use data set options with the CNTLIN= and CNTLOUT= data set options. See Section 2, "Fundamental Concepts for Using Base SAS Procedures," for a list.

PROC FORMAT < option(s) >;

To do this

Use this option

Specify a SAS data set from which PROC FORMAT builds informats or formats

CNTLIN=

Create a SAS data set that stores information about informats or formats

CNTLOUT=

Print information about informats or formats

FMTLIB

Specify a SAS library or catalog that will contain the informats or formats that you are creating in the PROC FORMAT step

LIBRARY=

Specify the number of characters of the informatted or formatted value that appear in PROC FORMAT output

MAXLABLEN=

Specify the number of characters of the start and end values that appear in the PROC FORMAT output

MAXSELEN=

Prevent a new informat or format from replacing an existing one of the same name

NOREPLACE

Print information about each format and informat on a separate page [1]

PAGE

[1] Used in conjunction with FMTLIB. If PAGE is specified, FMTLIB is invoked (or assumed).

Options

CNTLIN= input-control-SAS-data-set

  • specifies a SAS data set from which PROC FORMAT builds informats and formats. CNTLIN= builds formats and informats without using a VALUE, PICTURE, or INVALUE statement. If you specify a one-level name, then the procedure searches only the default data library (either the WORK data library or USER data library) for the data set, regardless of whether you specify the LIBRARY= option.

    Note: LIBRARY= can point to either a data library or a catalog. If only a libref is specified, a catalog name of FORMATS is assumed.

  • Tip: A common source for an input control data set is the output from the CNTLOUT= option of another PROC FORMAT step.

  • See also: Input Control Data Set on page 460

  • Featured in: Example 5 on page 472

CNTLOUT= output-control-SAS-data-set

  • creates a SAS data set that stores information about informats and formats that are contained in the catalog specified in the LIBRARY= option.

  • Note: LIBRARY= can point to either a data library or a catalog. If only a libref is specified, then a catalog name of FORMATS is assumed.

  • If you are creating an informat or format in the same step that the CNTLOUT= option appears, then the informat or format that you are creating is included in the CNTLOUT= data set.

  • If you specify a one-level name, then the procedure stores the data set in the default data library (either the WORK data library or the USER data library), regardless of whether you specify the LIBRARY= option.

  • Tip: You can use an output control data set as an input control data set in subsequent PROC FORMAT steps.

  • See also: Output Control Data Set on page 458

FMTLIB

  • prints information about all the informats and formats in the catalog that is specified in the LIBRARY= option. To get information only about specific informats or formats, subset the catalog using the SELECT or EXCLUDE statement.

  • Interaction: The PAGE option invokes FMTLIB.

  • Tip: If your output from FMTLIB is not formatted correctly, then try increasing the value of the LINESIZE= system option.

  • Tip: If you use the SELECT or EXCLUDE statement and omit the FMTLIB and CNTLOUT= options, then the procedure invokes the FMTLIB option and you receive FMTLIB option output.

  • Featured in: Example 6 on page 476

LIBRARY= libref<.catalog>

  • specifies a catalog to contain informats or formats that you are creating in the current PROC FORMAT step. The procedure stores these informats and formats in the catalog that you specify so that you can use them in subsequent SAS sessions or jobs.

  • Note: LIBRARY= can point to either a data library or a catalog. If only a libref is specified, then a catalog name of FORMATS is assumed.

  • Alias: LIB=

  • Default: If you omit the LIBRARY= option, then formats and informats are stored in the WORK.FORMATS catalog. If you specify the LIBRARY= option but do not specify a name for catalog , then formats and informats are stored in the libref .FORMATS catalog.

  • Tip: SAS automatically searches LIBRARY.FORMATS. You might want to use the LIBRARY libref for your format catalog. You can control the order in which SAS searches for format catalogs with the FMTSEARCH= system option. For further information about FMTSEARCH=, see the section on SAS system options in SAS Language Reference: Dictionary .

  • See also: Storing Informats and Formats on page 456

  • Featured in: Example 1 on page 464

MAXLABLEN= number-of-characters

  • specifies the number of characters in the informatted or formatted value that you want to appear in the CNTLOUT= data set or in the output of the FMTLIB option. The FMTLIB option prints a maximum of 40 characters for the informatted or formatted value.

MAXSELEN= number-of-characters

  • specifies the number of characters in the start and end values that you want to appear in the CNTLOUT= data set or in the output of the FMTLIB option. The FMTLIB option prints a maximum of 16 characters for start and end values.

NOREPLACE

  • prevents a new informat or format that you are creating from replacing an existing informat or format of the same name. If you omit NOREPLACE, then the procedure warns you that the informat or format already exists and replaces it.

    Note: You can have a format and an informat of the same name.

PAGE

  • prints information about each format and informat (that is, each entry) in the catalog on a separate page.

    Tip: The PAGE option activates the FMTLIB option.

EXCLUDE Statement

Excludes entries from processing by the FMTLIB and CNTLOUT= options.

Restriction: Only one EXCLUDE statement can appear in a PROC FORMAT step.

Restriction: You cannot use a SELECT statement and an EXCLUDE statement within the same PROC FORMAT step.

EXCLUDE entry(s) ;

Required Arguments

entry(s)

  • specifies one or more catalog entries to exclude from processing. Catalog entry names are the same as the name of the informat or format that they store. Because informats and formats can have the same name, and because character and numeric informats or formats can have the same name, you must use certain prefixes when specifying informats and formats in the EXCLUDE statement. Follow these rules when specifying entries in the EXCLUDE statement:

    • Precede names of entries that contain character formats with a dollar sign ($).

    • Precede names of entries that contain character informats with an at sign and a dollar sign (for example, @$ entry-name ).

    • Precede names of entries that contain numeric informats with an at sign (@).

    • Specify names of entries that contain numeric formats without a prefix.

Shortcuts to Specifying Names

You can use the colon (:) and hyphen (-) wildcard characters to exclude entries. For example, the following EXCLUDE statement excludes all formats or informats that begin with the letter a .

 exclude a:; 

In addition, the following EXCLUDE statement excludes all formats or informats that occur alphabetically between apple and pear , inclusive:

 exclude apple-pear; 

FMTLIB Output

If you use the EXCLUDE statement without either FMTLIB or CNTLOUT= in the PROC FORMAT statement, then the procedure invokes FMTLIB.

INVALUE Statement

Creates an informat for reading and converting raw data values.

Featured in: Example 4 on page 470.

See also: The section on informats in SAS Language Reference: Dictionary for documentation on informats supplied by SAS.

INVALUE <$> name <( informat-option(s) )>

< value-range-set(s) >;

To do this

Use this option

Specify the default length of the informat

DEFAULT=

Specify a fuzz factor for matching values to a range

FUZZ=

Specify a maximum length for the informat

MAX=

Specify a minimum length for the informat

MIN=

Store values or ranges in the order that you define them

NOTSORTED

Left-justify all input strings before they are compared to ranges

JUST

Uppercase all input strings before they are compared to ranges

UPCASE

Required Arguments

name

  • names the informat that you are creating.

  • Requirement: The name must be a valid SAS name. A numeric informat name can be up to 31 characters in length; a character informat name can be up to 30 characters in length and cannot end in a number. If you are creating a character informat, then use a dollar sign ($) as the first character; this is why a character informat is limited to 30 characters.

  • Restriction: A user-defined informat name cannot be the same as an informat name that is supplied by SAS.

  • Interaction: The maximum length of an informat name is controlled by the VALIDFMTNAME= SAS system option. See SAS Language Reference: Dictionary for details on VALIDFMTNAME=.

  • Tip: Refer to the informat later by using the name followed by a period. However, do not use a period after the informat name in the INVALUE statement.

  • Tip: When SAS prints messages that refer to a user-written informat, the name is prefixed by an at sign (@). When the informat is stored, the at sign is prefixed to the name that you specify for the informat; this is why the name is limited to 31 or 30 characters. You need to use the at sign only when you are using the name in an EXCLUDE or SELECT statement; do not prefix the name with an at sign when you are associating the informat with a variable.

Options

The following options are common to the INVALUE, PICTURE, and VALUE statements and are described in Informat and Format Options on page 451:

  • DEFAULT= length

  • FUZZ= fuzz-factor

  • MAX= length

  • MIN= length

  • NOTSORTED

In addition, you can use the following options:

JUST

  • left-justifies all input strings before they are compared to the ranges.

UPCASE

  • converts all raw data values to uppercase before they are compared to the possible ranges. If you use UPCASE, then make sure the values or ranges you specify are in uppercase.

  • value-range-set(s)

    • specifies raw data and values that the raw data will become. The value-range-set(s) can be one or more of the following:

      • value-or-range-1 < , value-or-range-n>=informatted-value [ existing-informat ]

      • The informat converts the raw data to the values of informatted-value on the right side of the equal sign.

    • informatted-value

      • is the value you want the raw data in value-or-range to become. Use one of the following forms for informatted-value :

      • character-string

        • is a character string up to 32,767 characters long. Typically, character-string becomes the value of a character variable when you use the informat to convert raw data. Use character-string for informatted-value only when you are creating a character informat. If you omit the single or double quotation marks around character-string , then the INVALUE statement assumes that the quotation marks are there.

          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.

      • number

        • is a number that becomes the informatted value. Typically, number becomes the value of a numeric variable when you use the informat to convert raw data. Use number for informatted-value when you are creating a numeric informat. The maximum for number depends on the host operating environment.

      • _ERROR_

        • treats data values in the designated range as invalid data. SAS assigns a missing value to the variable, prints the data line in the SAS log, and issues a warning message.

      • _SAME_

        • prevents the informat from converting the raw data as any other value. For example, the following GROUP . informat converts values 01 through 20 and assigns the numbers 1 through 20 as the result. All other values are assigned a missing value.

           invalue group 01-20= _same_                other= .; 
    • existing-informat

      • is an informat that is supplied by SAS or a user-defined informat. The informat you are creating uses the existing informat to convert the raw data that match value-or-range on the left side of the equals sign. If you use an existing informat, then enclose the informat name in square brackets (for example, [date9.]) or with parentheses and vertical bars, for example, (date9.). Do not enclose the name of the existing informat in single quotation marks.

    • value-or-range

      • See Specifying Values or Ranges on page 453.

      • Consider the following examples:

        • The $GENDER. character informat converts the raw data values F and M to character values '1' and '2' :

           invalue $gender 'F'='1'                  'M'='2'; 

          The dollar sign prefix indicates that the informat converts character data.

        • When you are creating numeric informats, you can specify character strings or numbers for value-or-range . For example, the TRIAL. informat converts any character string that sorts between A and M to the number 1 and any character string that sorts between N and Z to the number 2. The informat treats the unquoted range 1 “3000 as a numeric range, which includes all numeric values between 1 and 3000:

           invalue trial 'A'-'M'=1                'N'-'Z'=2                 1-3000=3; 

          If you use a numeric informat to convert character strings that do not correspond to any values or ranges, then you receive an error message.

        • The CHECK. informat uses _ERROR_ and _SAME_ to convert values of 1 through 4 and 99. All other values are invalid:

           invalue check 1-4=_same_                 99=.              other=_error_; 

PICTURE Statement

Creates a template for printing numbers.

Featured in: Example 1 on page 464 and Example 9 on page 482

See also: The section on formats in SAS Language Reference: Dictionary for documentation on formats supplied by SAS.

PICTURE name <( format-option(s) )>

  • value-range-set-1 <( picture-1-option(s) )>

  • < value-range-set-n <( picture-n-option(s) )>>>;

To do this

Use this option

Control the attributes of the format

 

Specify that you can use directives in the picture as a template to format date, time, or datetime values

DATATYPE=

 

Specify the default length of the format

DEFAULT=

 

Specify the separator character for the fractional part of a number

DECSEP=

 

Specify the three-digit separator character for a number

DIG3SEP=

 

Specify a fuzz factor for matching values to a range

FUZZ=

 

Specify a maximum length for the format

MAX=

 

Specify a minimum length for the format

MIN=

 

Specify multiple pictures for a given value or range and for overlapping ranges

MULTILABEL

 

Store values or ranges in the order that you define them

NOTSORTED

 

Round the value to the nearest integer before formatting

ROUND

Control the attributes of each picture in the format

 

Specify a character that completes the formatted value

FILL=

 

Specify a number to multiply the variable s value by before it is formatted

MULTIPLIER =

 

Specify that numbers are message characters rather than digit selectors

NOEDIT

 

Specify a character prefix for the formatted value

PREFIX=

Required Arguments

name

  • names the format you are creating.

  • 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, not ending in a number. If you are creating a character format, then use a dollar sign ($) as the first character, which is why a character informat is limited to 30 characters.

  • Restriction: A user-defined format cannot be the name of a format supplied by SAS.

  • Interaction: The maximum length of a format name is controlled by the VALIDFMTNAME= SAS system option. See SAS Language Reference: Dictionary for details on VALIDFMTNAME=.

  • Tip: Refer to the format later by using the name followed by a period. However, do not put a period after the format name in the VALUE statement.

Options

The following options are common to the INVALUE, PICTURE, and VALUE statements and are described in Informat and Format Options on page 451:

  • DEFAULT= length

  • FUZZ= fuzz-factor

  • MAX= length

  • MIN= length

  • NOTSORTED

In addition, you can use the following arguments:

DATATYPE=DATE TIME DATETIME

  • specifies that you can use directives in the picture as a template to format date, time, or datetime values. See the definition and list of directives on page 442.

    Tip: If you format a numeric missing value, then the resulting label will be ERROR. Adding a clause to your program that checks for missing values can eliminate the ERROR label.

DECSEP= character

  • specifies the separator character for the fractional part of a number.

  • Default: . (a decimal point)

DIG3SEP= character

  • specifies the three-digit separator character for a number.

  • Default: , (a comma)

FILL= character

  • specifies a character that completes the formatted value. If the number of significant digits is less than the length of the format, then the format must complete, or fill, the formatted value:

    • The format uses character to fill the formatted value if you specify zeros as digit selectors.

    • The format uses zeros to fill the formatted value if you specify nonzero digit selectors. The FILL= option has no effect.

  • If the picture includes other characters, such as a comma, which appear to the left of the digit selector that maps to the last significant digit placed, then the characters are replaced by the fill character or leading zeros.

  • Default: (a blank)

  • Interaction: If you use the FILL= and PREFIX= options in the same picture, then the format places the prefix and then the fill characters.

  • Featured in: Example 9 on page 482

MULTILABEL

  • allows the assignment of multiple labels or external values to internal values. The following PICTURE statements show the two uses of the MULTILABEL option. In each case, number formats are assigned as labels. The first PICTURE statement assigns multiple labels to a single internal value. Multiple labels may also be assigned to a single range of internal values. The second PICTURE statement assigns labels to overlapping ranges of internal values. The MULTILABEL option allows the assignment of multiple labels to the overlapped internal values.

     picture abc (multilabel)     1000='9,999'     1000='9999';  picture overlap (multilabel)     /* without decimals */     0-999='999'     1000-9999='9,999'     /* with decimals */     0-9='9.999'     10-99='99.99'     100-999='999.9'; 
  • 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. For example, in the first PICTURE statement, the primary label for 1000 is 1,000 because the format 9,999 is the first external value that is assigned to 1000. The secondary label for 1000 is 1000, based on the 9999 format.

  • In the second PICTURE statement, the primary label for 5 is 5.000 based on the 9.999 format that is assigned to the range 0 “9 because 0 “9 is sequentially the first range of internal values containing 5. The secondary label for 5 is 005 because the range 0 “999 occurs in sequence after the range 0 “9. Consider carefully when you assign multiple labels to an internal value. Unless you use the NOTSORTED option when you assign variables, the SAS System stores the variables in sorted order. This may produce unexpected results when variables with the MULTILABEL format are processed . For example, in the second PICTURE statement, the primary label for 15 is 015, and the secondary label for 15 is 15.00 because the range 0 “999 occurs in sequence before the range 10 “99. If you want the primary label for 15 to use the 99.99 format, then you might want to change the range 10 “99 to 0 “99 in the PICTURE statement. The range 0 “99 occurs in sequence before the range 0 “999 and will produce the desired result.

MULTIPLIER= n

  • specifies a number that the variable s value is to be multiplied by before it is formatted. For example, the following PICTURE statement creates the MILLION. format, which formats the variable value 1600000 as $1.6M :

     picture million low-high='00.0M'         (prefix='$' mult=.00001); 
  • Alias: MULT=

  • Default: 10 n , where n is the number of digits after the first decimal point in the picture. For example, suppose your data contains a value 123.456 and you want to print it using a picture of 999.999 . The format multiplies 123.456 by 10 3 to obtain a value of 123456, which results in a formatted value of 123.456 .

  • Example: Example 1 on page 464

NOEDIT

  • specifies that numbers are message characters rather than digit selectors; that is, the format prints the numbers as they appear in the picture. For example, the following PICTURE statement creates the MILES. format, which formats any variable value greater than 1000 as > 1000 miles :

     picture miles 1-1000='0000'            1000<-high='>1000 miles'(noedit); 

PREFIX= prefix

  • specifies a character prefix to place in front of the value s first significant digit. You must use zero digit selectors or the prefix will not be used.

    The picture must be wide enough to contain both the value and the prefix. If the picture is not wide enough to contain both the value and the prefix, then the format truncates or omits the prefix. Typical uses for PREFIX= are printing leading currency symbols and minus signs. For example, the PAY. format prints the variable value 25500 as $25,500.00 :

     picture pay low-high='000,009.99'                       (prefix='$'); 
  • Default: no prefix

  • Interaction: If you use the FILL= and PREFIX= options in the same picture, then the format places the prefix and then the fill characters.

  • Featured in: Example 1 on page 464 and Example 9 on page 482

ROUND

  • rounds the value to the nearest integer before formatting. Without the ROUND option, the format multiplies the variable value by the multiplier, truncates the decimal portion (if any), and prints the result according to the template that you define. With the ROUND option, the format multiplies the variable value by the multiplier, rounds that result to the nearest integer, and then formats the value according to the template. Note that if the FUZZ= option is also specified, the rounding takes place after SAS has used the fuzz factor to determine which range the value belongs to.

    Tip: Note that the ROUND option rounds a value of .5 to the next highest integer.

value-range-set

  • specifies one or more variable values and a template for printing those values. The value-range-set is the following:

      value-or-range-1 <   , value-or-range-n>=picture   picture  
    • specifies a template for formatting values of numeric variables. The picture is a sequence of characters in single quotation marks. The maximum length for a picture is 40 characters. Pictures are specified with three types of characters: digit selectors, message characters, and directives. You can have a maximum of 16 digit selectors in a picture.

      Digit selectors are numeric characters (0 through 9) that define positions for numeric values. A picture format with nonzero digit selectors prints any leading zeros in variable values; picture digit selectors of 0 do not print leading zeros in variable values. If the picture format contains digit selectors, then a digit selector must be the first character in the picture.

      Note: This chapter uses 9 s as nonzero digit selectors.

      Message characters are nonnumeric characters that print as specified in the picture. The following PICTURE statement contains both digit selectors (99) and message characters ( illegal day value ). Because the DAYS. format has nonzero digit selectors, values are printed with leading zeros. The special range OTHER prints the message characters for any values that do not fall into the specified range (1 through 31).

       picture days 01-31='99'          other='99-illegal day value'; 

      For example, the values 02 and 67 print as

       02  67-illegal day value 

      Directives are special characters that you can use in the picture to format date, time, or datetime values.

      Restriction: You can only use directives when you specify the DATATYPE= option in the PICTURE statement.

      The permitted directives are

      %a

      Locale s abbreviated weekday name

      %A

      Locale s full weekday name

      %b

      Locale s abbreviated month name

      %B

      Locale s full month name

      %d

      Day of the month as a decimal number (1 “31), with no leading zero

      %H

      Hour (24- hour clock) as a decimal number (0 “23), with no leading zero

      %I

      Hour (12-hour clock) as a decimal number (1 “12), with no leading zero

      %j

      Day of the year as a decimal number (1 “366), with no leading zero

      %m

      Month as a decimal number (1 “12), with no leading zero

      %M

      Minute as a decimal number (0 “59), with no leading zero

      %p

      Locale s equivalent of either AM or PM

      %S

      Second as a decimal number (0 “59), with no leading zero

      %U

      Week number of the year (Sunday as the first day of the week) as a decimal number (0,53), with no leading zero

      %w

      Weekday as a decimal number (1= Sunday, 7=Saturday)

      %y

      Year without century as a decimal number (0 “99), with no leading zero

      %Y

      Year with century as a decimal number

      %%

      %

      Any directive that generates numbers can produce a leading zero, if desired, by adding a 0 before the directive. This applies to %d, %H, %I, %j, %m, %M, %S, %U, and %y. For example, if you specify %y in the picture, then 2001 would be formatted as 1 , but if you specify %0y, then 2001 would be formatted as 01 .

      Tip: Add code to your program to direct how you want missing values to be displayed.

value-or-range

  • See Specifying Values or Ranges on page 453.

Building a Picture Format: Step by Step

This section shows how to write a picture format for formatting numbers with leading zeros. In the SAMPLE data set, the default printing of the variable Amount has leading zeros on numbers between 1 and ˆ’ 1:

 options nodate pageno=1 linesize=64 pagesize=60;  data sample;     input Amount;     datalines;  -2.051  -.05  -.017    0   .093   .54   .556  6.6  14.63  ;  proc print data=sample;     title 'Default Printing of the Variable Amount';  run; 
 Default Printing of the Variable Amount         1               Obs     Amount                1      -2.051                2      -0.050                3      -0.017                4       0.000                5       0.093                6       0.540                7       0.556                8       6.600                9      14.630 

The following PROC FORMAT step uses the ROUND format option and creates the NOZEROS. format, which eliminates leading zeros in the formatted values:

 libname library '  SAS-data-library  ';  proc format library=library;     picture nozeros (round)             low -  -1  =  '00.00'                (prefix='-')             -1 <-< 0  =     '99'                (prefix='-.' mult=100)              0  -< 1  =     '99'                (prefix='.' mult=100)              1  - high =  '00.00';  run; 

The following table explains how one value from each range is formatted. Figure 23.1 on page 446 provides an illustration of each step. The circled numbers in the figure correspond to the step numbers in the table.

Table 23.1: Building a Picture Format

Step

Rule

In this example

1

Determine into which range the value falls and use that picture.

In the second range, the exclusion operator < appears on both sides of the hyphen and excludes ˆ’ 1 and 0 from the range.

2

Take the absolute value of the numeric value.

Because the absolute value is used, you need a separate range and picture for the negative numbers in order to prefix the minus sign.

3

Multiply the number by the MULT= value. If you do not specify the MULT= option, then the PICTURE statement uses the default. The default is 10 n , where n is the number of digit selectors to the right of the decimal [1] in the picture. (Step 6 discusses digit selectors further.)

Specifying a MULT= value is necessary for numbers between 0 and 1 and numbers between 0 and -1 because no decimal appears in the pictures for those ranges. Because MULT= defaults to 1, truncation of the significant digits results without a MULT= value specified. ( Truncation is explained in the next step.) For the two ranges that do not have MULT= values specified, the MULT= value defaults to 100 because the corresponding picture has two digit selectors to the right of the decimal. After the MULT= value is applied, all significant digits are moved to the left of the decimal.

4

Truncate the number after the decimal. If the ROUND option is in effect, then the format rounds the number after the decimal to the next highest integer if the number after the decimal is greater than or equal to .5.

Because the example uses MULT= values that ensured that all of the significant digits were moved to the left of the decimal, no significant digits are lost. The zeros are truncated.

5

Turn the number into a character string. If the number is shorter than the picture, then the length of the character string is equal to the number of digit selectors in the picture. Pad the character string with leading zeros. (The results are equivalent to using the Zw. format. Zw. is explained in the section on SAS formats in SAS Language Reference: Dictionary .

The numbers 205, 5, and 660 become the character strings 020 5, 05 , and 0660 , respectively. Because each picture is longer than the numbers, the format adds a leading zero to each value. The format does not add leading zeros to the number 55 because the corresponding picture only has two digit selectors.

6

Apply the character string to the picture. The format only maps the rightmost n characters in the character string, where n is the number of digit selectors in the picture. Thus, it is important to make sure that the picture has enough digit selectors to accommodate the characters in the string. After the format takes the rightmost n characters, it then maps those characters to the picture from left to right. Choosing a zero or nonzero digit selector is important if the character string contains leading zeros. If one of the leading zeros in the character string maps to a nonzero digit selector, then it and all subsequent leading zeros become part of the formatted value. If all of the leading zeros map to zero digit selectors, then none of the leading zeros become part of the formatted value; the format replaces the leading zeros in the character string with blanks. [2]

The leading zero is dropped from each of the character strings 0205 and 0660 because the leading zero maps to a zero digit selector in the picture.

7

Prefix any characters that are specified in the PREFIX= option. You need the PREFIX= option because when a picture contains any digit selectors, the picture must begin with a digit selector. Thus, you cannot begin your picture with a decimal point, minus sign, or any other character that is not a digit selector.

The PREFIX= option reclaims the decimal point and the negative sign, as shown with the formatted values -.05 and .55 .

[1] A decimal in a PREFIX= option is not part of the picture.

[2] You can use the FILL= option to specify a character other than a blank to become part of the formatted value.

click to expand
Figure 23.1: Formatting One Value in Each Range

The following PROC PRINT step associates the NOZEROS. format with the AMOUNT variable in SAMPLE. The output shows the result of rounding.

 proc print data=sample noobs;     format amount nozeros.;     title Formatting the Variable Amount';     title2 'with the NOZEROS. Format';  run; 
 Formatting the Variable Amount         1     with the NOZEROS. Format              Amount              -2.05               -.05               -.02                .00                .09                .54                .56               6.60              14.63 

CAUTION:

  • The picture must be wide enough for the prefix and the numbers. In this example, if the value ˆ’ 45.00 were formatted with NOZEROS. then the result would be 45.00 because it falls into the first range, low - ˆ’ 1, and the picture for that range is not wide enough to accommodate the prefixed minus sign and the number.

Specifying No Picture

This PICTURE statement creates a picture-name format that has no picture:

 picture  picture-name  ; 

Using this format has the effect of applying the default SAS format to the values.

SELECT Statement

Selects entries from processing by the FMTLIB and CNTLOUT= options.

Restriction: Only one SELECT statement can appear in a PROC FORMAT step.

Restriction: You cannot use a SELECT statement and an EXCLUDE statement within the same PROC FORMAT step.

Featured in: Example 6 on page 476.

SELECT entry(s) ;

Required Arguments

entry(s)

  • specifies one or more catalog entries for processing. Catalog entry names are the same as the name of the informat or format that they store. Because informats and formats can have the same name, and because character and numeric informats or formats can have the same name, you must use certain prefixes when specifying informats and formats in the SELECT statement. Follow these rules when specifying entries in the SELECT statement:

    • Precede names of entries that contain character formats with a dollar sign ($).

    • Precede names of entries that contain character informats with an at sign and a dollar sign, for example, @$ entry-name .

    • Precede names of entries that contain numeric informats with an at sign (@).

    • Specify names of entries that contain numeric formats without a prefix.

Shortcuts to Specifying Names

You can use the colon (:) and hyphen (-) wildcard characters to select entries. For example, the following SELECT statement selects all formats or informats that begin with the letter a .

 select a:; 

In addition, the following SELECT statement selects all formats or informats that occur alphabetically between apple and pear , inclusive:

 select apple-pear; 

FMTLIB Output

If you use the SELECT statement without either FMTLIB or CNTLOUT= in the PROC FORMAT statement, then the procedure invokes FMTLIB.

VALUE Statement

Creates a format that specifies character strings to use to print variable values.

Featured in: Example 2 on page 466.

See also: The chapter about formats in SAS Language Reference: Dictionary for documentation about SAS formats.

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

  • < value-range-set(s) >;

To do this

Use this option

Specify the default length of the format

DEFAULT=

Specify a fuzz factor for matching values to a range

FUZZ=

Specify a maximum length for the format

MAX=

Specify a minimum length for the format

MIN=

Specify multiple values for a given range, or for overlapping ranges

MULTILABEL

Store values or ranges in the order that you define them

NOTSORTED

Required Arguments

name

  • names the format that you are creating.

  • 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 and cannot end in a number. If you are creating a character format, then use a dollar sign ($) as the first character.

  • Restriction: The name of a user-defined format cannot be the same as the name of a format that is supplied by SAS.

  • Interaction: The maximum length of a format name is controlled by the VALIDFMTNAME= SAS system option. See SAS Language Reference: Dictionary for details about VALIDFMTNAME=.

  • Tip: 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.

Options

The following options are common to the INVALUE, PICTURE, and VALUE statements and are described in Informat and Format Options on page 451:

  • DEFAULT= length

  • FUZZ= fuzz-factor

  • MAX= length

  • MIN= length

  • NOTSORTED

In addition, you can use the following options:

MULTILABEL

  • allows 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 may 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 2 5'     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. For 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.

value-range-set(s)

  • specifies one or more variable values and a character string or an existing format.

  • The value-range-set(s) can be one or more of the following:

    • value-or-range-1 < , value-or-range-n>= formatted-value [ existing-format ]

  • The variable values on the left side of the equals sign print as the character string on the right side of the equals sign.

  • formatted-value

    • specifies a character string that becomes the printed value of the variable value that appears on the left side of the equals 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.

    • Requirement: 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 "(pass)"     F=Female "(pass)"; 
    • Requirement: 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 supplied by SAS or an existing user-defined format. The format you are creating uses the existing format to convert the raw data that match value-or-range on the left side of the equals sign.

      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 .

      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.

    • Tip: Avoid nesting formats more than one level. The resource requirements can increase dramatically with each additional level.

  • value-or-range

    • For details on how to specify value-or-range , see Specifying Values or Ranges on page 453.

    • Consider the following examples:

      • 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.

      • The numeric format ANSWER. writes the values 1 and 2 as yes and no :

         value answer 1='yes'               2='no'; 

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.




Base SAS 9.1.3 Procedures Guide (Vol. 1)
Base SAS 9.1 Procedures Guide, Volumes 1, 2, 3 and 4
ISBN: 1590472047
EAN: 2147483647
Year: 2004
Pages: 260

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net