|
地板

楼主 |
发表于 2011-12-12 23:55:51
|
只看该作者
Re: 如何以分组、组合的方式来求得结果
[code:2i5fhxne]data test;
input num $ group $ compare &:$20.;
cards;
01 merry A B C D
02 merry A B E G H
03 merry B E
04 merry AA R
05 agit W X Y
06 agit G HH
07 wang A C DD W Z
08 wang B C DD Z
09 wang C W
10 yang A S
;
data out;
length num group $8 compare _num_ $20;
if _n_=1 then do;
declare hash h(dataset:'test',multidata:'y',hashexp:6,ordered:'y');
h.definekey('group');
h.definedata('num','compare');
h.definedone();
call missing (group,num,compare);
end;
set test;
rawgroup=group; rawnum=num; rawcompare=compare;
count=0; _num_='';
if (h.find()=0) then do;
if num ne rawnum then do;
do i=1 to count(compbl(compare),' ');
if indexw(rawcompare,scan(compare,i,' ')) gt 0 then count+1;
end;
if count gt 0 then _num_=num;
end;
do while(h.find_next()=0);
n=0;
if num ne rawnum then do;
do i=1 to count(compbl(compare),' ');
if indexw(rawcompare,scan(compare,i,' ')) gt 0 then n+1;
end;
if count=n and n>0 then _num_=catx(',',_num_,num);
else if n>count then do;
_num_=num;
count=n;
end;
end;
end;
end;
group=rawgroup; num=rawnum; compare=rawcompare;
keep _num_ num group compare;
run;[/code:2i5fhxne] |
|