Hello,
I found this very helpful post on how to add a prefix like '+' to values, but found, as the last reply to that post suggests, that it doesn't work for non-integers like 0.1. I guess this has something to do with the fact that "The prefix is placed in front of the value's first significant digit" (documentation).
So my question is how do I get values like 0.1 to display like +0.1 ?
proc format;
picture test
0<-high= '0.0' (prefix='+');
run;
data hello;
input x;
cards;
0.1
;
run;
data _null_;
set hello;
call symputx('whatever',put(x,test.));
run;
%put &whatever.;I get +1, but am trying to get +0.1. The Fill option just gives me something like 0+1.
Would appreciate any tips.
Thanks very much!
You would need to define each order of magnitude as a separate range:
0-<10 = ' 9.0' (prefix='+')
10-<100 = ' 90.0' (prefix='+')
etc.
Make a couple of changes to your format definition ... including leaving room for the prefix:
proc format;
picture test 0<-high= ' 9.0' (prefix='+');
run;
You may still have difficulty with larger numbers, but this will take care of the case that you asked about.
Thank you! Worked perfectly.
So....if I change to 0<-high= ' 10.0' (prefix='+');, then I can make it work for values like 15.1...but this adds an extra 0 for 0.1, giving me +00.1
Is there a way I can make it work for a whole range of values (0.1 --> +0.1, 15.5 --> +15.5, 100.3 --> +100.3, same for negatives)? I.e., keep the number as it would have been otherwise, but just add a prefix?
Thanks very much!
You would need to define each order of magnitude as a separate range:
0-<10 = ' 9.0' (prefix='+')
10-<100 = ' 90.0' (prefix='+')
etc.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.