变量cy标识循环次数,以数据集msim1为基准,目标是从prep1+prep2+prep3和最小处开始寻找,两次循环数据一直,结果却不同,不知道问题出在哪里,请高手指教,多谢!
data msim1;
input id1 cy1 prep1;
cards;
1 1 0.1
2 1 0.2
3 1 0.3
4 2 0.1 
5 2 0.2
6 2 0.3
;
run;
data msim2;
input id2 cy2 prep2;
cards;
11 1 0.9
12 1 0.8
13 1 0.2
14 1 0.1
16 2 0.9
17 2 0.8
18 2 0.2
19 2 0.1
;
run;
data msim3;
input id3 cy3 prep3;
cards;
21 1 0.9
22 1 0.2
23 1 0.5
24 1 0.1
25 1 0.3
26 2 0.9 
27 2 0.2
28 2 0.5
29 2 0.1 
30 2 0.3
;
run;
data match(keep=idtreat idcontrol idcontrol1 distance cy1 cy2 cy3);
length id2 prep2 id3 prep3 8;
if _N_=1 then do;
declare hash h(hashexp:8,dataset: 'msim2',ordered: 'no');
declare hiter iter('h');
h.defineKey('id2');
h.defineData('id2','prep2','cy2');
h.defineDone();
declare hash j(hashexp:8,dataset: 'msim3',ordered: 'no');
declare hiter ite('j');
j.defineKey('id3');
j.defineData('id3','prep3','cy3');
j.defineDone();
call missing(id2,prep2,cy2,id3,prep3,cy3);
end;
set msim1;
retain distance 5;
rc3=iter.first();
rc4=ite.first();
if (rc3=0 or rc4=0) then distance=5;
do while (rc3=0 or rc4=0);
scoredistance=prep1+prep2+prep3;
if scoredistance<distance and cy1=cy2=cy3 then do;
distance=scoredistance;
idtreat=id1;
idcontrol=id2;
idcontrol1=id3;
end;
rc3=iter.next();
rc4=ite.next();
if (rc3^=0 and rc4^=0) then do;
output;
rc1=h.remove(key: idcontrol);
rc2=j.remove(key: idcontrol1);
end;
end;
run;