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!
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;
answer=strip(put(round(number,.1),8.1));
run;
Just to be sure, you want the value -0.00001 to be displayed as 0.0, correct?
Yes, exactly! Just 0.0
Thank you!
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.
I tried that, but it then gets rid of my decimal place and I am just left with '0'
So do you just want a format to the number to be decimal X.1?
So like...
format answer 17.1;
(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?
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'
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?
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;
answer=strip(put(round(number,.1),8.1));
run;
Thank you so much, that worked so well!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.