Solved
Contributor
Posts: 51

# Picture Format - Adding a Prefix to non-integers

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!

Accepted Solutions
Solution
‎06-18-2018 08:54 PM
Super User
Posts: 6,785

## Re: Picture Format - Adding a Prefix to non-integers

You would need to define each order of magnitude as a separate range:

0-<10 = ' 9.0' (prefix='+')

10-<100 = ' 90.0' (prefix='+')

etc.

All Replies
Super User
Posts: 6,785

## Re: Picture Format - Adding a Prefix to non-integers

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.

Contributor
Posts: 51

## Re: Picture Format - Adding a Prefix to non-integers

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!

Solution
‎06-18-2018 08:54 PM
Super User
Posts: 6,785

## Re: Picture Format - Adding a Prefix to non-integers

You would need to define each order of magnitude as a separate range:

0-<10 = ' 9.0' (prefix='+')

10-<100 = ' 90.0' (prefix='+')

etc.

Contributor
Posts: 51