|
|
沙发

楼主 |
发表于 2010-8-11 09:09:31
|
只看该作者
Re: 怎么用一步hash实现重复值的计数
[code:2k7xb4cw]data ex;
input num1 num2;
cards;
2 1
2 1
2 1
2 1
5 1
5 2
5 1
5 2
6 1
6 5
6 2
6 5
6 5
6 1
6 5
6 2
;
data _null_;
if _n_=1 then
do;
declare hash h(hashexp:16,ordered:'yes');
h.definekey('num1');
h.definedata('num1','num2','k');
h.definedone();
call missing(num1,num2,k);
end;
set ex(rename=(num2=temp)) end=last;
if h.find()=0 then do;
k+1;
if temp>num2 then num2=temp;
rc=h.replace(key:num1,data:num1,data:num2,data:k);
end;
else rc=h.add(key:num1,data:num1,data:num2,data:1);
if last then h.output(dataset:'out');
run;
proc print;
run;[/code:2k7xb4cw] |
|