Previous Page | Next Page

Formats

Syntax

SAS formats have the following form:

<$>format<w>.<d>

where

$

indicates a character format; its absence indicates a numeric format.

format

names the format. The format is a SAS format or a user-defined format that was previously defined with the VALUE statement in PROC FORMAT. For more information about user-defined formats, see The FORMAT Procedure in Base SAS Procedures Guide.

w

specifies the format width, which for most formats is the number of columns in the output data.

d

specifies an optional decimal scaling factor in the numeric formats.

Formats always contain a period (.) as a part of the name. If you omit the w and the d values from the format, SAS uses default values. The d value that you specify with a format tells SAS to display that many decimal places. Formats never change or truncate the internally stored data values.

For example, in DOLLAR10.2, the w value of 10 specifies a maximum of 10 columns for the value. The d value of 2 specifies that two of these columns are for the decimal part of the value, which leaves eight columns for all the remaining characters in the value. The remaining columns include the decimal point, the remaining numeric value, a minus sign if the value is negative, the dollar sign, and commas, if any.

If the format width is too narrow to represent a value, SAS tries to squeeze the value into the space available. Character formats truncate values on the right. Numeric formats sometimes revert to the BESTw.d format. SAS prints asterisks if you do not specify an adequate width. In the following example, the result is x=**.

x=123;
put x= 2.;

If you use an incompatible format, such as using a numeric format to write character values, SAS first attempts to use an analogous format of the other type. If this attempt fails, an error message that describes the problem appears in the SAS log.

When the value of d is greater than fifteen, the precision of the decimal value after the 15th decimal place might not be accurate.

Previous Page | Next Page | Top of Page