Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom format for SAS

Tags:

format

sas

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.

like image 416
Mark Romano Avatar asked Jul 09 '26 03:07

Mark Romano


1 Answers

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;
like image 184
Joe Avatar answered Jul 11 '26 19:07

Joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!