Reputation: 711
Hi I'm interested in making a couple of slightly complex custom formats for data I produce in SAS. I need it to be of the numeric type.
FORMAT 1
0="-"
>0="<number>%"
<0="<number>%"
ie
0 >>>>>>> -
.74 >>>>> 74%
-.65>>>>> -65%
FORMAT 2
0="-"
>0="$<number(with commas)>"
<0="$(<number(with commas)>"
ie
0>>>>>>-
1467>>>>$1,467
-39087>>$(39,087)
I've made simple custom formats using code like this
proc format;
picture test
0='-';
run;
But I'm not sure how to write the syntax to append the $
sign and (
)
signs.
Thanks.
Upvotes: 3
Views: 619
Reputation: 63434
The percent format is fairly straightforward. The dollar one is a mite trickier as you have to watch your widths.
Basically you need to use prefix
to get anything on the front (dollar, paren, minus sign) and just put anything that you want at the end actually at the end. '0' means a sometimes-printing digit, '9' means always-printing digit.
You use mult
to make the .13 -> 13%.
And, for dollar, you can make use of the dollar
format. You might also be able to use the NEGPAREN
format on the negative side, but you can't combine that with the dollar sign...
proc format;
picture pctfmt
low - <0= '000%' (mult=100 prefix='-')
0 = '-'
0<-high = '000%' (mult=100);
picture dollfmt
low - <0 = '000,000,000.00)' (prefix='$(')
0 = '-'
0 <- high = [dollar16.2]
;
run;
data _null_;
input x;
put x= pctfmt.;
datalines;
-.15
-.05
0
.05
.15
;;;;
run;
data _null_;
input x;
put x= dollfmt12.2;
datalines;
-5.93
-13432554
0
12345324
5.98
;;;;
run;
Upvotes: 5