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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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