SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 755|回复: 0
打印 上一主题 下一主题

请教sas/hash问题

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2010-5-2 17:20:13 | 只看该作者

请教sas/hash问题

三组数据匹配会报错,如果把注释二去掉,即数据集bb的观测可重复利用即可,不知道是什么原因。另外,注释一处没有起到取三者和最小值的作用,请高手指教。
data aa;
input n1 id1 f1;
cards;
1 1 0.279103244
1 2 0.423331188
1 3 0.468192815
1 4 0.424473077
2 5 0.298561304
2 6 0.313567808
2 7 0.527609991
2 8 0.317669888
3 9 0.342632588
3 10 0.498541723
3 11 0.375768989
3 12 0.377146096
;
data bb;
input n2 id2 f2;
cards;
1 13 0.356242929
1 14 0.44764805
1 15 0.48368379
1 16 0.441579713
1 17 0.322713805
1 18 0.490257199
1 19 0.701382686
1 20 0.421768935
2 21 0.409891761
2 22 0.336426959
2 23 0.564979922
2 24 0.340961356
2 25 0.435482576
2 26 0.423822678
2 27 0.600047163
2 28 0.320887932
3 29 0.391996276
3 30 0.537861812
3 31 0.408102109
3 32 0.378189334
3 33 0.411606792
3 34 0.477971239
3 35 0.289566708
3 36 0.427040361
;
data cc;
input n3 id3 f3;
cards;
1 37 0.329143126
1 38 0.400794463
1 39 0.432646156
1 40 0.392089002
1 41 0.290059121
1 42 0.451998602
1 43 0.513093355
1 44 0.451948013
2 45 0.39674351
2 46 0.292887287
2 47 0.518306132
2 48 0.297867081
2 49 0.409592958
2 50 0.372189187
2 51 0.546214109
2 52 0.276230669
3 53 0.360550965
3 54 0.43107428
3 55 0.251990394
3 56 0.387600035
3 57 0.400069633
3 58 0.552321202
3 59 0.464109421
3 60 0.307850897
;
data dd(keep=distance idnew1 idnew2 idnew3 n1 n2 n3);
length id2 f2 id3 f3 8;
if _N_=1 then do;
declare hash h(dataset: 'bb',ordered: 'no');
declare hiter iter('h');
h.defineKey('id2');
h.defineData('id2','f2','n2');
h.defineDone();
declare hash y(dataset: 'cc',ordered: 'no');
declare hiter ite('y');
y.defineKey('id3');
y.defineData('id3','f3','n3');
y.defineDone();
call missing(id2,f2,n2,id3,f3,n3);
end;
set aa;
retain distance 2;
rc=iter.first();
rc=ite.first();
if (rc=0) then distance=1.5;
do while (rc=0);
scoredistance=f1+f2+f3;*注释一没有起到取最小值的作用;
if scoredistance<distance and n1=n2=n3 then do;
distance=scoredistance;
idnew1=id1;
idnew2=id2;
idnew3=id3;
end;
rc=iter.next();
rc=ite.next();
if (rc^=0) then do;
output;
rc1=h.remove(key: idnew2);*注释二此处会报错;
rc2=y.remove(key: idnew3);
end;
end;
run;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-4 06:42 , Processed in 0.065186 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表