Sample 24976: Specify a numeric format at run time
Use the PUTN function to conditionally apply a format at run time.
Note:
The FORMAT statement is a compile time statement. To apply a format based upon the variable's value, the FORMAT must be applied at execution instead.
The PUTC function enables you to specify a character format at run time.
/* Create a sample dset. TYPE designates whether */
/* it is interger (1) or decimal (2). */
data a;
input x type ;
datalines;
123 1
12.3 2
12 1
23.34 2
;
/* Create a format to specify which format to apply */
/* based upon value of TYPE. */
proc format;
value type 1='4.'
2='7.3';
run;
/* Apply format based upon variable value */
data new;
set a;
fmt=put(type,type.);
value=putn(x,fmt);
run;
proc print;
run;
Obs x type fmt value
1 123.00 1 4. 123
2 12.30 2 7.3 12.300
3 12.00 1 4. 12
4 23.34 2 7.3 23.340
Use the PUTN function to conditionally apply a format at run time.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Special SAS Reference ==> Procedures ==> FORMAT
|
| Date Modified: | 2005-12-16 03:03:01 |
| Date Created: | 2005-01-13 13:19:14 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |