一个示例是数据集:
data have;
input observations $;
datalines;
'a-b-c'
'b-c-a'
'c-a-b'
'd-e'
'e-d'
'a-b'
'a-b-c-d'
'b-a-d-c'
'a-b-c-e'
;
run;
我不确定如何将彼此组合的所有观察结果映射到某种combo_id。所需数据的示例:
'a-b-c' combo_1
'b-c-a' combo_1
'c-a-b' combo_1
'd-e' combo_2
'e-d' combo_2
'a-b' combo_3
'a-b-c-d' combo_4
'b-a-d-c' combo_4
'a-b-c-e' combo_5
在这一点上,我将能够按sql中的combo_id分组...
data have;
input x $20.;
cards;
a-b-c
b-c-a
c-a-b
d-e
e-d
a-b
a-b-c-d
b-a-d-c
a-b-c-e
;
run;
data want;
set have;
retain string grp num;
if countw(x) ^=num then do;
grp+1;
string=x;
end;
else do;
array var [5] $1 _temporary_;
call missing (of var(*));
do i=1 to countw(x);
var(i)=scan(x,i);
end;
call sortc(of var(*));
_string=catx('-',of var(*));
if _string^=string then grp=grp+1;
end;
group=cats('Comb_',grp);
num=countw(x);
if not missing (_string) then string=_string;
else string=x;
keep x group;
run;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句