Reputation: 325
How can I avoid double rounding when using the round
function and put
function in SAS together? Take the following code for example:
data _null_;
sd = 11.863499608;
sdc = strip(put(round(sd,0.0001),10.3));
put sdc=;
run;
The actual result should be 11.863
but the put
function rounds up from the already rounded value of 11.8635
to give a final result of 11.864
.
Could someone please tell me how to avoid the second round up by the put
function? Please note that the first round
function is extremely important and can't be avoided.
Upvotes: 0
Views: 4259
Reputation: 9109
There are situations where Fw.d format does not round as expected. It is best to round to desired number and decimals before using the format.
20 data _null_;
21 x=0-1e-5;
22 put x=best.;
23 y = put(x,5.2);
24 put y= 'Negative 0 need to round';
25 z = put(round(x,.01),5.2);
26 put z=;
27 run;
x=-0.00001
y=-0.00 Negative 0 need to round
z=0.00
Upvotes: 1