|
沙发

楼主 |
发表于 2011-1-25 17:43:04
|
只看该作者
Re: sas中的哈希表
data Treatment;
input pscoreT idT k1@@;
datalines;
0.110 1 1
0.130 6 1
0.110 2 1
0.112 9 2
0.113 11 2
0.115 12 2
;
data Control;
input pscoreC idC k2@@;
datalines;
0.334 3 1
0.110 5 1
0.131 4 1
0.120 7 2
0.132 8 2
0.125 10 2
;
data Matched(keep= IdSelectedControl MatchedToTreatID);
if _N_= 1 then do;
if 0 then set Control;
declare hash h(dataset: "Control", ordered: 'no');
declare hiter iter('h');
h.defineKey('idC','k2');
h.defineData(all:"yes");
h.defineDone();
call missing(idC, pscoreC);
end;
set Treatment;
retain BestDistance 99;
rc= iter.first();
if (rc=0) then BestDistance= 99;
do while (rc= 0);
if k1=k2 then do;
ScoreDistance= abs(pscoreT - pscoreC);
if ScoreDistance < BestDistance then do;
BestDistance= ScoreDistance;
IdSelectedControl= idC;
MatchedToTreatID= idT;
MatchedK=k2;
end;
end;
rc= iter.next();
if (rc~= 0) then do;
output;
rc1= h.remove(key: IdSelectedControl,key:MatchedK);
end;
end;
run; |
|