Can someone suggest a fix that will make the "<0.5%" format work?
proc format; picture custpcttwo /*format values above .5% as whole percentages*/ .005-high='0009%' (round) (mult=100) /*for those btw 0 and .5% format as "<0.5%"*/ low-<.005 = '<0.5%' ; run; data a; x=.005; y=.0003; run; proc print data=a; var x y; format x y custpcttwo.; run;
Yes, as long as you move the round picture option to right after the picture format name.
...
picture custpcttwo (round)
...
edited to include complete solution:
You'll want to add a (noedit) picture option after the '<0.5%' since you're not using digit selectors.
proc format; picture custpcttwo /*format values above .5% as whole percentages*/ .005-high='0009%' (round) (mult=100) /*for those btw 0 and .5% format as "<0.5%"*/ low-<.005 = '<0.5%' (noedit) ; run;
Reference: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0n990vq8gxca6n1vnsracr6jp2c.htm
I ran the following code:
proc format ;
picture custpcttwo (round)
/*format values above .5% as whole percentages*/
.005-high='0009%' (mult=100)
/*for those btw 0 and .5% format as "<0.5%"*/
low-<.005 = '<0.5%' (noedit)
;
run;
data a;
x=.005;
y=.0003;
run;
proc print data=a;
var x y;
format x y custpcttwo.;
run;
and got:
![]()
Hi @Batman, you'll want to add a (noedit) picture option after the '<0.5%' since you're not using digit selectors.
proc format; picture custpcttwo /*format values above .5% as whole percentages*/ .005-high='0009%' (round) (mult=100) /*for those btw 0 and .5% format as "<0.5%"*/ low-<.005 = '<0.5%' (noedit) ; run;
Reference: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0n990vq8gxca6n1vnsracr6jp2c.htm
Where you able to get it to work when you ran it? For me, the formatted value of "y" is still "0%"
Yes, I ran the following code:
proc format;
picture custpcttwo
/*format values above .5% as whole percentages*/
.005-high='0009%' (mult=100)
/*for those btw 0 and .5% format as "<0.5%"*/
low-<.005 = '<0.5%' (noedit)
;
run;
data a;
x=.005;
y=.0003;
run;
proc print data=a;
var x y;
format x y custpcttwo.;
run;
and got:
I should mention that you also have to move the round picture option since it applies to all values:
proc format;
picture custpcttwo (round)
/*format values above .5% as whole percentages*/
.005-high='0009%' (mult=100)
/*for those btw 0 and .5% format as "<0.5%"*/
low-<.005 = '<0.5%' (noedit)
;
run;
Sorry I forgot to mention, I'd still like to be able to round the value of "x", so it should be 1%. Is that doable?
Yes, as long as you move the round picture option to right after the picture format name.
...
picture custpcttwo (round)
...
edited to include complete solution:
You'll want to add a (noedit) picture option after the '<0.5%' since you're not using digit selectors.
proc format; picture custpcttwo /*format values above .5% as whole percentages*/ .005-high='0009%' (round) (mult=100) /*for those btw 0 and .5% format as "<0.5%"*/ low-<.005 = '<0.5%' (noedit) ; run;
Reference: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0n990vq8gxca6n1vnsracr6jp2c.htm
I ran the following code:
proc format ;
picture custpcttwo (round)
/*format values above .5% as whole percentages*/
.005-high='0009%' (mult=100)
/*for those btw 0 and .5% format as "<0.5%"*/
low-<.005 = '<0.5%' (noedit)
;
run;
data a;
x=.005;
y=.0003;
run;
proc print data=a;
var x y;
format x y custpcttwo.;
run;
and got:
![]()
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.