Quartz | Level 8

## How to get rid of negative in front of zero

Hi,

I have this line of code that is calculating the mean of a variable. For a couple variables, the mean is a very high negative number (-0.00001) and because I only want one decimal place, SAS ends up printing the mean as -0.0. Is there a way to get rid of this negative sign

This is the code that I am using:

data statall (keep=trt_dec row1 row2 row3 row4 vid);
merge sesstat(in=a) median;
by vid trt_dec;
if a;
row1=strip(put(n,8.0));
if mean ne . then row2=strip(put(mean, 8.1))||' ('||strip(put(std, 8.2))||')';
if mean =. then row2='-';
if median ne . then row3=strip(put(round(median, .1), 8.1))||' ('||strip(put(min, 8.0))||', '||strip(put(max, 8.0))||')';
if median =. then row3='-';
row4='('||strip(put(uclm, 8.1))||', '||strip(put(lclm, 8.1))||')';
run;

Thank you, any help is appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Quartz | Level 8

## Re: How to get rid of negative in front of zero

Put converts your numeric data into character data.  your code SHOULD already be returning a result of 0.0, I am not sure why it isn't so I think something else is going on.

MY suggestion was to keep the data as numeric and simply use an actual FORMAT Answer 8.1;

What do you get when you run the following code?  The second observation should return 0.0, are you seeing only 0?

data ShoWUser;
infile datalines delimiter=',';
input Number
;
datalines;
15.514
-0.00001
9523.51
3960.26
;

data yay;
set ShoWUser;
run;

10 REPLIES 10
Tourmaline | Level 20

## Re: How to get rid of negative in front of zero

Just to be sure, you want the value -0.00001 to be displayed as 0.0, correct?

Quartz | Level 8

## Re: How to get rid of negative in front of zero

Yes, exactly! Just 0.0

Thank you!

Calcite | Level 5

## Re: How to get rid of negative in front of zero

Is there a method to display -0.00001 as -0.0? Rounding method is removing the negative sign. Want to see a method which retains the negative sign.

Super User

Quartz | Level 8

## Re: How to get rid of negative in front of zero

I tried that, but it then gets rid of my decimal place and I am just left with '0'

Quartz | Level 8

## Re: How to get rid of negative in front of zero

So do you just want a format to the number to be decimal X.1?

So like...

(17 needs to be big enough to fit your largest integer obviously i just used it as an example)....

So as other users have noticed round your number using round(VAL,.1)  and then simply format the new number you came up with?

Super User

## Re: How to get rid of negative in front of zero

In addition to rounding, use a proper display format with one decimal.

@kmardinian wrote:

I tried that, but it then gets rid of my decimal place and I am just left with '0'

Quartz | Level 8

## Re: How to get rid of negative in front of zero

Can you give me an example of a proper display format?  Is that not the 8.1 format I used in my code above after the mean variable?

Quartz | Level 8

## Re: How to get rid of negative in front of zero

Put converts your numeric data into character data.  your code SHOULD already be returning a result of 0.0, I am not sure why it isn't so I think something else is going on.

MY suggestion was to keep the data as numeric and simply use an actual FORMAT Answer 8.1;

What do you get when you run the following code?  The second observation should return 0.0, are you seeing only 0?

data ShoWUser;
infile datalines delimiter=',';
input Number
;
datalines;
15.514
-0.00001
9523.51
3960.26
;

data yay;
set ShoWUser;