Hi All,
I request you to help me rounding mean value -0.00015367 to -0.000 , when i round by using below code
STRIP(PUT(round(MEAN,0.001),8.3)); I am getting 0.000
If I increase decimals to round(MEAN,0.0001) {x=STRIP(PUT(round(MEAN,0.0001),8.3)); }
in order to get -0.000 but this may effect other data ,if possible please do help me with other way of doing..
Thanks in Advance..
I believe you could make this work via a custom format.
proc format;
value fin_fmt(default=10)
-0.0005 <-< 0 = '-0.000'
other =[f32.3]
;
run;
data test;
do i= -0.001 to +0.001 by 0.000001;
value_num=i;
value_char=put(i,fin_fmt.);
value_round=round(i,0.001);
output;
end;
format value_num fin_fmt. i best32.;
run;
Please dont round just convert as below
data have;
x=-0.00015367;
x2=put(x,8.3);
put x2=;
run;
Thanks for quick response.
Your below code gives required output (It truncates ) for that record when i had 0.000XXX but i required do rounding when i had value other then zero value
@ettinenivarma wrote:
Hi All,
I request you to help me rounding mean value -0.00015367 to -0.000 , when i round by using below code
STRIP(PUT(round(MEAN,0.001),8.3)); I am getting 0.000
If I increase decimals to round(MEAN,0.0001) {x=STRIP(PUT(round(MEAN,0.0001),8.3)); }
in order to get -0.000 but this may effect other data ,if possible please do help me with other way of doing..
Thanks in Advance..
So maybe you mean something different by the word "rounding" than the ROUND function in SAS means, and something different than the normal mathematical meaning of the word "rounding".
You are doing this "rounding" and creating characters, not numbers, is that really what you want? If so, then I think your code works, and I don't understand the point of your question.
I also don't understand "but this may effect [sic] other data". Could you explain?
Yes your correct i mean to say round funcation it self ,Yes my end varaible should be char.
Other data means ,in my varaible i had many observation like mean ,sd values etc..
for example : when i round -0.00015367 by using above code i get 0.000 but my requirment is -0.000.
Thanks for your response
Would the following suffice?:
data have; input mean; rmean=round(MEAN,.001); if mean lt 0 then rmean=rmean-.00001; x=PUT(rmean,8.3); cards; -0.00015367 0 0.00015367 ;
Art, CEO, AnalystFinder.com
But could not do hardcoding ".00001" because that variable may contain other values in real time data
Thanks your post sir
Yes, I can not do hardcording of values...
Couldn't you do hard coding for that one case? e.g.:
data have; input mean; rmean=round(MEAN,.001); if mean lt 0 and rmean eq 0 then rmean=rmean-.00001; x=PUT(rmean,8.3); cards; -0.00015367 0 0.00015367 ;
Art, CEO, AnalystFinder.com
@ettinenivarma You use the same function, we don't have your code or data or computer in front of us so you're not going to get something that's exact for your code. The 'hardcoding' is for testing and demonstration purposes with the intention that you take the formula and use it on your data with your own variables.
Please disregard above, this is not correct for your situation. Note that 0 is well 0, there's no sign attached to it, which is why you're seeing those results.
The solution proposed by @Jagadishkatam seems to produce what you want though, otherwise you're probably likely to need to create your own custom function/format.
want = put(myVariable, 8.3);
Hi Reeza,
Thanks for response.
I to convenced same to my boss saying 0 is 0 there will not be any sign to it, he said as it is financial data he wants as suggested above. I already tryied applying round function and put as well but I want to trying different way of doing to get minus.
Any way thanks all for suggestion and inputs
I believe you could make this work via a custom format.
proc format;
value fin_fmt(default=10)
-0.0005 <-< 0 = '-0.000'
other =[f32.3]
;
run;
data test;
do i= -0.001 to +0.001 by 0.000001;
value_num=i;
value_char=put(i,fin_fmt.);
value_round=round(i,0.001);
output;
end;
format value_num fin_fmt. i best32.;
run;
I believe a custom format is the easiest solution for you.
Financial reports often use Proc Report and should your boss be very demanding then you can also add conditional formatting to make him/her happy as documented here: http://support.sas.com/kb/23/353.html
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.