@cx2019 wrote:
How to transform negative value of a SAS numeric variable into parenthesized accounting amount, for example -7.8 into ($7.8)
Personally I wouldn't transform any value as that makes it hard to do arithmetic as needed.
Unless you really think that you need the $ for clarity I would use the NEGPAREN format.
If you actually really need a both parentheses and the dollar sign you need a custom format similar to below:
proc format libarary=work;
picture dollarparen
low -<0 = '000009.90)' (prefix='($')
0-high = '000009.90' (prefix='$')
;
run;
data example;
input x;
datalines;
123.4
-7.8
0.04
-1234.56
;
run;
proc print data=example;
format x dollarparen.;
run;
In the format definition the nines and zeroes are digit selectors the 9 before the decimal will always appear as a 0 value if nothing assigned in that position. Add leading zeroes if you need to display longer values.