PUT Function


Returns a value using a specified format

Category: Special

Syntax

PUT ( source , format .)

Arguments

source

  • identifies the SAS variable or constant whose value you want to reformat . The source argument can be character or numeric.

format .

  • contains the SAS format that you want applied to the variable or constant that is specified in the source. To override the default alignment, you can add an alignment specification to a format:

    -L

    left aligns the value.

    -C

    centers the value.

    -R

    right aligns the value.

  • Restriction: The format . must be of the same type as the source, either character or numeric.

Details

If the PUT function returns a value to a variable that has not yet been assigned a length, by default the variable length is determined by the width of the format.

The format must be the same type (numeric or character) as the value of source . The result of the PUT function is always a character string. If the source is numeric, the resulting string is right aligned. If the source is character, the result is left aligned.

Use PUT to convert a numeric value to a character value. PUT writes (or produces a reformatted result) only while it is executing. To preserve the result, assign it to a variable.

Comparisons

The PUT statement and the PUT function are similar. The PUT function returns a value using a specified format. You must use an assignment statement to store the value in a variable. The PUT statement writes a value to an external destination (either the SAS log or a destination you specify).

Examples

Example 1: Converting Numeric Values to Character Value

In this example, the first statement converts the values of CC, a numeric variable, into the four-character hexadecimal format, and the second writes the same value that the PUT function returns.

 cchex=put(cc,hex4.);  put cc hex4.; 

Example 2: Using PUT and INPUT Functions

In this example, the PUT function returns a numeric value as a character string. The value 122591 is assigned to the CHARDATE variable. The INPUT function returns the value of the character string as a SAS date value using a SAS date informat. The value 11681 is stored in the SASDATE variable.

 numdate=122591;  chardate=put(numdate,z6.);  sasdate=input(chardate,mmddyy6.); 

See Also

Functions:

  • 'INPUT Function' on page 592

  • 'INPUTC Function' on page 594

  • 'INPUTN Function' on page 596

  • 'PUTC Function' on page 756,

  • 'PUTN Function' on page 758

Statement:

  • 'PUT Statement' on page 1342




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

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