Sentry Page Protection
Variable Attributes [10-17]
Comma. and Dollar. Format
The (Comma.) and (Dollar.) formats display the value with the comma separator and the dollar sign ($).
Example
Example
Again, let's take a look at Num1 and Num2.
Example: (Comma.)
Data WD1;
Set Num;
Format Num2 Comma.;
Run;
The (Comma.) format displays the comma separator.
E.g. 12345.67 --> 12,346
However, the decimal places are gone!
In order to display the decimal places, you must use the CommaW.D format.
Example (Comma9.2)
Data WD2;
Set Num;
Format Num2 Comma9.2;
Run;
Two decimal places are displayed.
Please note that you need the width (W) of 9 to display the full value since the comma also counts as 1 digit.
E.g. Data = 12,345.67
In total, you need a minimum width of 9 to display the full value.
Let's take a look at another example.
Example (DollarW.D)
Data WD3;
Set Num;
Format Num2 Dollar10.2;
Run;
- 12 = 2 digits
- , = 1 digit
- 345 = 3 digits
- .(dot) = 1 digit
- 67 = 2 digits
In total, you need a minimum width of 9 to display the full value.
Let's take a look at another example.
Example (DollarW.D)
Data WD3;
Set Num;
Format Num2 Dollar10.2;
Run;
The (Dollar10.2) format displays the comma separator as well as the dollar sign ($) at before the dollar amount.
E.g. 12345.67 --> $12,346
Again, you need to add 1 extra digit to the width (W) since the dollar sign ($) takes up 1 digit as well.
In total, you need a minimum width of 10 to display the full value.
Exercise
Copy and run the TRANSAC data set from the yellow box below.
Copy and run the TRANSAC data set from the yellow box below.
The sales tax is 14.75%.
Create a new variable that computes the total after tax:
Total(After tax) = Total(Before tax) x 14.75%
Display the after-tax total at 2 decimal places.
Need some help?
HINT:
Make sure you count the dollar sign ($) and the comma separator (,) as 1 digit each.
SOLUTION:
Data Transac2;
Set Transac;
Format total2 dollar9.2;
Total2 = total*1.1475;
Run;
Fill out my online form.