第1引数を第2引数の最も近い倍数(第2引数が省略された場合は最も近い整数)に丸めます。
| カテゴリ: | 切り捨て |
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;
point_three=0.3 three_times_point_one=0.3 difference=-5.55112E-17
ROUND(0.33,0.1)は、標準の入力形式にあわせて結果を3/10として計算します。次のステートメントでは期待される結果が生成されます。
if round(x, 0.1)=0.3 then
... more SAS statements ...if round(x, 0.1)=y then
... more SAS statements ...if round(x, 0.1)=round(y, 0.1) then
... more SAS statements ...ROUND(argument, rounding-unit)は、結果の有効桁数が9以下で、次のいずれかの条件が該当する場合、10進算術演算で期待される結果を生成します。
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;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 _null_; difference=round(1234.56789, .11111) - 11111*.11111; put difference=; run;
difference=0
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;data testfile;
do i=1 to 17;
value=0.5 - 10**(-i);
epsilon=min(1e-6, value * 1e-12);
temp=value + .5 + epsilon;
fraction=modz(temp, 1);
round=temp - fraction;
output;
end;
run;
proc print data=testfile noobs;
format value 19.16;
run;