|
8#
楼主 |
发表于 2010-4-22 23:19:53
|
只看该作者
Re: 求助:按照指定条件随机配对
Obviously the code for Hopewell runs much faster than mine. But only for giving another view of this problem....firstly i numbered each case and cotrol and then matched them by the ordered number; in the resulted data, cases with missing matched control are those that cannot find the matched part in control group. On the other hand, if you are sure all the IDs in the two data sets are unique, you can use the IDs to do sampling directly .
[code:22vivtap]data Control Control_; set Control; RecordControl+1; output Control; output Control_; run;
data Case Case_ ; set Case ; RecordCase +1; output Case ; output Case_ ; run;
%macro SelectMcr(v6,RecordCase);
proc sql;
create table control_1 as
select RecordControl, v6 from Control_ where v6 between &v6-200 and &v6+200;
quit;
proc surveyselect data = control_1 method = srs seed = 11 n = 1 out = Matched noprint;
run;
data Control_;
merge Control_ Matched (in = m); by RecordControl;
if not m;
run;
data Matched;
set Matched;
matchedCase = &recordCase;
run;
proc append base = base data = Matched force; run;
%mend SelectMcr;
data base;
length RecordControl v6 matchedCase 8.;
delete;
run;
data _null_;
set Case_;
call execute('%SelectMcr('||v6||','||RecordCase||')');
run;
data Match_Results;
set base;
lagRcordControl = lag(RecordControl);
if RecordControl = lagRcordControl then call missing(RecordControl, v6);
keep RecordControl matchedCase;
rename RecordControl = MatchedControl matchedCase = Case;
run;[/code:22vivtap] |
|