Base SAS 9.1 Procedures Guide, Volumes 1, 2, 3 and 4

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) >;

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

CNTLOUT= output-control-SAS-data-set

FMTLIB

LIBRARY= libref<.catalog>

MAXLABLEN= number-of-characters

MAXSELEN= number-of-characters

NOREPLACE

PAGE

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)

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

Options

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

In addition, you can use the following options:

JUST

UPCASE

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) )>

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

Options

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

In addition, you can use the following arguments:

DATATYPE=DATE TIME DATETIME

DECSEP= character

DIG3SEP= character

FILL= character

MULTILABEL

MULTIPLIER= n

NOEDIT

PREFIX= prefix

ROUND

value-range-set

value-or-range

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.

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:

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)

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) )>

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

Options

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

In addition, you can use the following options:

MULTILABEL

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';

value-range-set(s)

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.

Категории