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

I need to create/use a format that does the following:

 

displays dollar amounts $xxxx,xx - > when zero or positive

($xxx,xxx) <-in red when negative

 

I tried doing picture formats and could not get it to work properly. 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Use Traffic Light .

 

data have;
input id x;
cards;
1 10000
2 -10000
;
run;


proc format ;
value fmt
 low-<0='red';
 run;

ods pdf file='c:\temp\x.pdf';

proc report data=have nowd;
column id x;
define id/display;
define x/display style={foreground=fmt.};
run;

ods pdf close;

View solution in original post

4 REPLIES 4
Reeza
Super User

@Doug____ wrote:

I need to create/use a format that does the following:

 

displays dollar amounts $xxxx,xx - > when zero or positive

($xxx,xxx) <-in red when negative

 

I tried doing picture formats and could not get it to work properly. 


Can you show what you've tried so far? A picture format is the right approach here. Or you could create custom formats using a function and then use nested formats. 

 

Doug____
Pyrite | Level 9

Actually I think I got it about two minutes after posting as follows:

 

proc format;

   picture dollar

      0-high   = '0,000,009' (prefix = '$')

    low-<0   = '0,000,009)' (prefix = '^S={color = red}($');

run;

ballardw
Super User
proc format library = work cntlout=work.fmt;
picture negdollar  
low -<0 = '00,000,000,000,009.99)' (prefix='($'  )
0-high  = [dollar21.2]
;
run;

data example;
   input x;
   y= -1*x;
datalines;
1
12
123
1234
12345
123456
1234567
12345678
;
run;

proc print data=example;
  format x y negdollar.;
run;
Ksharp
Super User

Use Traffic Light .

 

data have;
input id x;
cards;
1 10000
2 -10000
;
run;


proc format ;
value fmt
 low-<0='red';
 run;

ods pdf file='c:\temp\x.pdf';

proc report data=have nowd;
column id x;
define id/display;
define x/display style={foreground=fmt.};
run;

ods pdf close;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1344 views
  • 1 like
  • 4 in conversation