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.
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;
@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.
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;
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.