Rounds the first argument to the nearest multiple of the second argument, or to the nearest integer when the second argument is omitted.
| Category: | Truncation |
data _null_; point_three=0.3; three_times_point_one=3*0.1; difference=point_three - three_times_point_one; put point_three= ; put three_times_point_one= ; put difference= ; run;
ROUND(0.33,0.1) computes the result as 3/10, and the
following statement produces the results that you would expect. if round(x,0.1) = 0.3 then
... more SAS statements ...if round(x,0.1) = y then
... more SAS statements ...if abs(x-y) <= 1e-12 * max( abs(x), abs(y) ) then
... more SAS statements ...ROUND(argument, rounding-unit) produces the result that
you expect from decimal arithmetic if the result has no more than
nine significant digits and any of the following conditions are true:
options pageno=1 nodate;
data rounding;
d1 = round(1234.56789,100) - 1200;
d2 = round(1234.56789,10) - 1230;
d3 = round(1234.56789,1) - 1235;
d4 = round(1234.56789,.1) - 1234.6;
d5 = round(1234.56789,.01) - 1234.57;
d6 = round(1234.56789,.001) - 1234.568;
d7 = round(1234.56789,.0001) - 1234.5679;
d8 = round(1234.56789,.00001) - 1234.56789;
d9 = round(1234.56789,.1111) - 1234.5432;
/* d10 has too many decimal places in the value for */
/* rounding-unit. */
d10 = round(1234.56789,.11111) - 1234.54321;
run;
proc print data=rounding noobs;
run;options pageno=1 nodate; data rounding2; drop pi unit; pi = arcos(-1); unit=1/7; d1=round(pi,unit) - 22/7; d2=round(pi, unit) - 22*unit; run; proc print data=rounding2 noobs; run;
data test;
do i=8 to 17;
value=0.5 - 10**(-i);
round=round(value);
output;
end;
do i=8 to 17;
value=-0.5 + 10**(-i);
round=round(value);
output;
end;
run;
proc print data=test noobs;
format value 19.16;
run;