PUT Function

Returns a value using a specified format.

Category: Special
Returned data type: NVARCHAR VARBINARY BINARY

Syntax

PUT(source, format.)

Arguments

source

identifies the variable or constant whose value you want to reformat.

Data type A data type that is supported by the format argument

format.

contains the SAS or FedSQL 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 the same type as the value of source

Details

The PUT function affects the output of the query in which it is specified. It temporarily modifies the data type of the specified input variable.
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 format constants and to output stored data in a different format. Use PUT to convert a numeric value to a character value. For more information, see How to Format Output with the PUT Function.

Comparisons

The CAST function permanently modifies the data type of the specified input variable. The PUT function affects the output of the query in which it is specified.

Example

The following statement illustrates the PUT function.
Statement
Result
select put(0.6666666667, fract8.);
2/3
select put(date(), date.);
19SEP13
select put(AvgLow, 4.1) from worldtemps;
45.0
33.0
17.0
68.0
56.0
57.0
28.0
51.0
75.0
36.0
33.0
25.0
Last updated: February 23, 2017