我有两组财务数据,由于单位错误,例如由于一个数据集中的$ 10000可能是另一个数据集中的$ 1000。
我正在尝试为这种差异编写检查代码,但是我能想到的唯一方法是将两个变量相除,看看差异是否在0.001、0.01、0.1、10、100等表格中,但是很难抓住所有差异。
是否有更聪明的方法来做到这一点?
使用proc compare
。确保两个数据集按行或特定组以相同的顺序排序。根据需要使用by
语句。有关选项的更多信息,请参见documentation。
示例-将修改后的cars
数据集与sashelp.cars
进行比较:
data cars_modified;
set sashelp.cars;
if(mod(_N_, 2) = 0) then msrp = msrp - 100;
run;
proc compare base = sashelp.cars
compare = cars_modified
out = out_differences
outnoequal
outdif
noprint;
var msrp;
run;
仅在out_differences
中输出有差异的观察结果:
_TYPE_ _OBS_ MSRP
DIF 2 $-100
DIF 4 $-100
DIF 6 $-100
DIF 8 $-100
DIF 10 $-100
...
所以您似乎要寻找X / Y是正好为1.00Exx的数字,其中XX是非0的整数的情况。
data _null_;
do x=1,10,100,1000;
do y=1,2,3,10.1,10 ;
ratio = x/y;
power = floor(log10(ratio));
if power ne 0 and 1.00 = round(ratio/10**power,0.01) then
put 'Ratio of ' x 'over ' y 'is 10**' power '.'
;
end;
end;
run;
结果:
Ratio of 1 over 10 is 10**-1 .
Ratio of 10 over 1 is 10**1 .
Ratio of 100 over 1 is 10**2 .
Ratio of 100 over 10 is 10**1 .
Ratio of 1000 over 1 is 10**3 .
Ratio of 1000 over 10 is 10**2 .