SAS中文论坛

标题: 检验数据双录入差异的macro [打印本页]

作者: shiyiming    时间: 2008-2-1 17:09
标题: 检验数据双录入差异的macro
该macro只输出有差异的数据.

%macro compare(base = , compare = , id = );
title 'Compare Results';
options ps = 60 ls = 100 nodate nonumber;
proc sort data = &base; by &id; run;
proc sort data = &compare; by &id; run;
proc compare data = &base compare = &compare out = temp (drop = _obs_) outbase outcomp outdif noprint;
id &id;
run;
proc transpose data = temp out = tempn;
var _numeric_;
by &id;
run;
data tempn;
set tempn;
format idname varname base compare $80.;
if _name_ = "&id" or col3 = 0 then delete;
idname = &id;
varname = _name_;
base = col1;
compare = col2;
keep &id idname varname base compare;
run;
proc transpose data = temp out = tempc;
var _character_;
by &id;
run;
data tempc;
set tempc;
format idname varname base compare $80.;
if _name_ = '_TYPE_' or col3 = '...' then delete;
idname = &id;
varname = _name_;
base = col1;
compare = col2;
keep &id idname varname base compare;
run;
data temp;
set tempn tempc;
run;
data temp;
set temp;
format baseflag compareflag $80.;
baseflag = "[ ]";
compareflag = "[ ]";
idname = left(idname);
base = left(base);
compare = left(compare);
run;
proc sort; by &id varname; run;
proc report data = temp nowindows headline headskip split = '^' missing;
column &id idname varname base baseflag compare compareflag;
define &id         / group   noprint;
define idname      / group   width = 10 flow "ID" left;
define varname     / display width = 20 flow "Variable" left;
define base        / display width = 20 flow "Base Dataset" left;
define baseflag    / display width = 10 flow "T/F" left;
define compare     / display width = 20 flow "Compared Dataset" left;
define compareflag / display width = 10 flow "T/F" left;
break after idname / skip;
compute before _page_;
line @1 100 * '_';
endcomp;
compute after _page_;
line @1 100 * '_';
endcomp;
run;
%mend compare;

data a;
do i = 1 to 9;
x = ceil(ranuni(0) * 3);
y = ceil(ranuni(0) * 3);
z = substr('abc', x, 1);
z2 = substr('abc', x, 1);
output;
end;
run;

data b;
do i = 1 to 9;
x = ceil(ranuni(0) * 3);
y = ceil(ranuni(0) * 3);
z = substr('abc', x, 1);
z2 = substr('abc', x, 1);
output;
end;
run;

%compare(base = a, compare = b, id = i);
作者: shiyiming    时间: 2008-2-1 17:32
标题: Re: 检验数据双录入差异的macro
看了一下,挺敢兴趣的,但程序太长,没有注释,也没细看,测试了一下,以下的浅见,也不一定对,仅供讨论
1、好像只对数据进行了确认,未对诸如变量名称、标签等进行全面确认
2、在数据比对一致的情况下,无任何结果报告

据我所知,SAS中有个系统宏变量SYSINFO,当运行compare过程之后,该变量包含了可能的错误信息(用数字表示),若无任何错误,&sysinfo=0
若能够利用这个变量进行报错,或许这个宏会变得容易些




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2