Chapter Contents |
Previous |
Next |
FORMAT |
Valid: | in a DATA step or PROC step |
Category: | Information |
Type: | Declarative |
Syntax | |
Arguments | |
Details | |
Comparisons | |
Examples | |
Example 1: Assigning Formats and Defaults | |
Example 2: Removing a Format | |
See Also |
Syntax |
FORMAT variable(s) <format>
<DEFAULT=default-format>; |
Tip: | To disassociate a format from a variable, use the variable in a FORMAT statement without specifying a format in a DATA step or in PROC DATASETS. In a DATA step, place this FORMAT statement after the SET statement. See Removing a Format. You can also use PROC DATASETS. |
Tip: | Formats that are associated with variables by using a FORMAT statement behave like formats that are used with a colon modifier in a subsequent PUT statement. For details on using a colon modifer, see PUT, List. |
See also: | Formats by Category |
A DEFAULT= format specification applies to
Default: | If you omit DEFAULT=, SAS uses BESTw. as the default numeric format and $w. as the default character format. |
Tip: | A DEFAULT= specification can occur anywhere in a FORMAT statement. It can specify either a numeric default, a character default, or both. |
Valid: | in a DATA step |
Featured in: | Assigning Formats and Defaults |
Details |
The FORMAT statement can use standard SAS formats or user-written formats that have been previously defined in PROC FORMAT. A single FORMAT statement can associate the same format with several variables, or it can associate different formats with different variables. If a variable appears in multiple FORMAT statements, SAS uses the format that is assigned last.
You use a FORMAT statement in the DATA step to permanently associate a format with a variable. SAS changes the descriptor information of the SAS data set that contains the variable. You can use a FORMAT statement in some PROC steps, but the rules are different. For more information, see SAS Procedures Guide.
Comparisons |
Examples |
This example uses a FORMAT statement to assign formats and default formats for numeric and character variables. The default formats are not associated with variables in the data set but affect how the PUT statement writes the variables in the current DATA step.
data tstfmt; format W $char3. Y 10.3 default=8.2 $char8.; W='Good morning.'; X=12.1; Y=13.2; Z='Howdy-doody'; put W/X/Y/Z; run; proc contents data=tstfmt; run; proc print data=tstfmt; run;
The following output shows a partial listing from PROC CONTENTS, as well as the report that PROC PRINT generates.
The SAS System 3 CONTENTS PROCEDURE -----Alphabetic List of Variables and Attributes----- # Variable Type Len Pos Format ---------------------------------------------- 1 W Char 3 16 $CHAR3. 3 X Num 8 8 2 Y Num 8 0 10.3 4 Z Char 11 19 |
The SAS System 4 OBS W Y X Z 1 Goo 13.200 12.1 Howdy-doody |
The default formats apply to variables X and Z while the assigned formats apply to the variables W and Y.
The PUT statement produces this result:
----+----1----+----2 Goo 12.10 3.200 Howdy-do
This example disassociates an existing format from a variable in a SAS data set. The order of the FORMAT and the SET statements is important.
data rtest; set rtest; format x; run;
See Also |
Statement:
| |||
The DATASETS Procedure in SAS Procedures Guide |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.