You can use the DOLLAR format option in SAS to print values in a column formatted as dollars with:
- A leading dollar sign
- Commas that separate every three digits
- A period that separates the decimal fraction
The following example shows how to use the DOLLAR format option in practice.
Example: Display Values in Dollar Format in SAS
Suppose we have the following dataset in SAS that contains information about the price of various products at some store:
/*create dataset*/
data my_data;
input product $ price;
datalines;
A 4134.50
B 13499.95
C 14695.99
D 1640.00
E 459.93
F 23.29
G 1005.38
;
run;
/*view dataset*/
proc print data=my_data;
Suppose we would like to format the values in the price column using a dollar format.
We can use the following syntax to do so:
/*view dataset and display price variable in dollar format*/
proc print data=my_data;
format price dollar10.2;
run;
Each value in the price column is displayed in a dollar format.
When using the dollar10.2 statement, the 10 specifies that a maximum of 10 characters will be needed to display the entire string including the dollar sign, commas and decimal place while the 2 specifies that 2 digits should be shown after the decimal place.
If you don’t want to display any values after the decimal place, you can use dollar8.0 instead:
/*view dataset and display price variable in dollar format without decimal places*/
proc print data=my_data;
format price dollar8.0;
run;
Notice that each value in the price column is rounded to the nearest dollar and each value after the decimal place has been truncated.
Note: You can find the complete documentation for the DOLLAR format in SAS here.
Additional Resources
The following tutorials explain how to perform other common tasks in SAS:
How to Use Proc Summary in SAS
How to Use Proc Tabulate in SAS
How to Use Proc Rank in SAS