Chapter Contents |
Previous |
Next |
Ways to Specify Formats |
You can use formats in the following ways:
amount=1145.32; put amount dollar10.2;The DOLLARw.d format in the PUT statement produces this result:
$1,145.32For more information, see the PUT statement in SAS Language Reference: Dictionary.
num=15; char=put(num,hex2.);The PUT function creates a character variable named CHAR that has a value of 0F.
The PUT function is useful for converting a numeric
value to a character value. For more information, see the PUT function in
SAS Language Reference: Dictionary.
%macro tst(amount); %put %sysfunc(putn(&amount,dollar10.2)); %mend tst; %tst (1154.23);For more information, see SAS Macro Language: Reference.
format sales1-sales3 comma10.2;Because the FORMAT statement permanently associates a format with a variable, any subsequent DATA step or PROC step uses COMMA10.2 to write the values of SALES1, SALES2, and SALES3. For more information, see the FORMAT statement in SAS Language Reference: Dictionary.
Note: Formats that you specify in a PUT statement behave
differently from those that you associate with a variable in a FORMAT statement.
The major difference is that formats that are specified in the PUT statement
will preserve leading blanks. If you assign formats with a FORMAT statement
prior to a PUT statement, all leading blanks are trimmed. The result is the
same as if you used the colon (:) format modifier. For details about using
the colon (:) format modifier, see the PUT, List statement in
SAS Language Reference: Dictionary.
attrib sales1-sales3 format=comma10.2;Because the ATTRIB statement permanently associates a format with a variable, any subsequent DATA step or PROC step uses COMMA10.2 to write the values of SALES1, SALES2, and SALES3. For more information, see the ATTRIB statement in SAS Language Reference: Dictionary.
Permanent versus Temporary Association |
Using a FORMAT statement or an ATTRIB statement in a PROC step associates a format with a variable for that PROC step, as well as for any output data sets that the procedure creates that contain formatted variables. For more information on using formats in SAS procedures, see the SAS Procedures Guide.
User-Defined Formats |
When you execute a SAS program that uses user-defined formats, these formats should be available. The two ways to make these formats available are
If you execute a program that cannot locate a user-defined format, the result depends on the setting of the FMTERR system option. If the user-defined format is not found, then these system options produce these results:
To avoid problems, make sure that your program has access to all user-defined formats that are used.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.