PUTN Function

Enables you to specify a numeric format at run time.

Category: Special

Syntax

PUTN(source, format.<,w<,d> > )

Required Arguments

source

specifies a numeric constant, variable, or expression to which you want to apply the format.

format.

is a character constant, variable, or expression with a value that is the numeric format you want to apply to source.

Optional Arguments

w

is a numeric constant, variable, or expression that specifies a width to apply to the format.

Interaction If you specify a width here, it overrides any width specification in the format.

d

is a numeric constant, variable, or expression that specifies the number of decimal places to use.

Interaction If you specify a number here, it overrides any decimal-place specification in the format.

Details

If the PUTN function returns a value to a variable that has not yet been assigned a length, by default the variable is assigned a length of 200.

Comparisons

The PUTC function enables you to specify a character format at run time.
The PUT function is faster than PUTN because PUT lets you specify a format at compile time rather than at run time.

Example

The PROC FORMAT step in this example creates a format, WRITFMT., that formats the variable values 1 and 2 with the name of a SAS date format. The DATA step creates a SAS data set from raw data consisting of a number and a key. After reading a record, the DATA step uses the value of KEY to create a variable, DATEFMT, that contains the value of the appropriate date format. The DATA step also creates a new variable, DATE, whose value is the formatted value of the date. PUTN assigns the value of DATE based on the value of NUMBER and the appropriate format.
proc format;
   value writfmt 1='date9.' 
                 2='mmddyy10.';
run;
data dates;
   input number key;
   datefmt=put(key,writfmt.);
   date=putn(number,datefmt);
   datalines;
15756 1
14552 2
;