全部,
我遇到了一些与 SAS 如何处理两个两位小数变量的减法相关的问题。这些结果被写入 DB2 数据库。此处使用的所有字段都导入到 SAS 并写入数据类型为 DECIMAL(19,2) 的 DB2 字段这是问题所在:
AL_AMT - PL_AMT = DIF_AMT
From SAS: 9,918,322.38 - 9,942,322.30 = (23,999.91)
Expected: 9,918,322.38 - 9,942,322.30 = (23,999.92)
这里有一些非常精简的代码片段。毫无疑问,SAS 很古怪。我希望有人可以帮助我发现它的许多怪癖中的哪一个可能导致了这种情况。
/* CAmt and PPmt are retrieved from a lengthy PROC SQL statement, */
/* their formats are unaltered. */
data WORK.TABLE1;
set WORK.TABLE0;
Difference = CAmt - PPmt;
run;
data WORK.TABLE2(keep=Rep:);
set WORK.TABLE1 end=last;
If _N_=1 then do;
Rep1CAmt=0;
Rep1PPmt=0;
Rep1Diff=0;
end;
Rep1CAmt+CAmt;
Rep1PPmt+PPmt;
Rep1Diff+Difference;
if last;
Rep1Diff=Rep1CAmt-Rep1PPmt;
Rep1Diff=round(Rep1Diff,.01);
/* I realize these two lines are redundant/unnecessary, but I was trying
different things to get the numbers to add up correctly, no such luck */
run;
data WORK.TABLE3;
set work.TABLE2;
AL_AMT=round(Rep1CAmt,.01);
PL_AMT=round(Rep1PPmt,.01);
DIF_AMT=AL_AMT-PL_AMT;
run;
proc append data=WORK.TABLE3 base=LIBNAME1.DB2TABLE(drop=ID) force;
run;