BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cx2019
Obsidian | Level 7

How to transform negative value of a SAS numeric variable into parenthesized accounting amount, for example -7.8 into ($7.8)

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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.

View solution in original post

2 REPLIES 2
ballardw
Super User

@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.

cx2019
Obsidian | Level 7

 Is there any way to add a suffix to a number directly, not to use  '000009.90)' ?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 907 views
  • 1 like
  • 2 in conversation