Is there a format to hide negative sign from numbers in SAS?

1000 Views Asked by At

I need to display negative numbers as positive (i.e. just hide the negative sign)

For that I'm currently using this format

proc format;
    * 9 forces leading zeros, 0 doesn't;
    * numbers are inversed so high = low;
    picture posval 
        low - high='000009.00'
        ;
    run;

But the problem is that in a gtl plot I will have 2 decimal values on the axis. I can't change the format of the axis tickvalues back to no decimals.

Since my numbers range from -6 to 0 and none of them are exactly integers I figured something like this but it's totally inelegant and is more a hack than a solution.

proc format;
    * 9 forces leading zeros, 0 doesn't;
    * numbers are inversed so high = low;
    picture posval 
        low -< -7 = '000009.00'
        -7 -< -7 = '0009'
        -7 -< -6 = '0009.00'
        -6 -< -6 = '0009'
        -6 -< -5 = '0009.00'
        -5 -< -5 = '0009'
        -5 -< -4 = '0009.00'
        -4 -< -4 = '0009'
        -4 -< -3 = '0009.00'
        -3 -< -3 = '0009'
        -3 -< -2 = '0009.00'
        -2 -< -2 = '0009'
        -2 -< -1 = '0009.00'
        -1 -< -1 = '0009'
        -1 -< -0 = '0009.00'
        0 -< 0 = '000009'
        0-high = '000009'
        ;
    run;

Is there a better way?

EDIT:
A bit more information: I purposely invert my values to negatives to draw them as inverted bars on a barchartparm (sas GTL).

2

There are 2 best solutions below

4
On

Why don't you use abs (absolute) function:

data abc;
input a;
cards;
-1
-2
-2.5
-3
2
3
3.05
4
;
run;


data abc1;
set abc;
a1 = abs(a);
run;

Output:

a      |  a1
-1     |  1
-2     |  2
-2.5   |  2.5
-3     |  3
2      |  2
3      |  3
3.05   |  3.05
4      |  4

Also, share the input output data sets if you have any different requirement.

2
On

Why not just create a user defined format to call the ABS() function?

proc format ;
 value abs low-high = [abs()] ;
run;