在 SAS 中,如果我有一个如下所示的字符串或数组,
array x[4] $1 ('A' 'B' 'C' 'D');
我需要生成元素的所有“独特”排列,如下所示,
[ABCD]
[ABC]
[BCD]
[ACD]
[ABD]
[AB]
[AC]
[AD]
[BC]
[BD]
[CD]
[A]
[B]
[C]
[D]
SAS中有一个函数可以生成数组的所有可能组合吗?
假设: 我相信你正在寻找combinations
并不是permutations
,所以顺序并不重要,BA
and AB
是同一件事。
Use call allcomb
子程序和comb
函数来找出可能的组合。
阅读更多关于allcomb
and comb
here
- http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0yx35py6pk47nn1vyrczffzrw25.htm http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0yx35py6pk47nn1vyrczffzrw25.htm
and here
- http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001009658.htm http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001009658.htm
简而言之 -
-
call allcomb
子程序给出了可能的组合n
元素时r
其中被采取并且
-
comb
函数给出了当超出时会有多少种组合n
元素r
其中的一些是一次拍摄的。
data test(keep=my_string);
length my_string $50.;
array a[4] $ ('A' 'B' 'C' 'D');
n = dim(a);
do k=1 to n;
do j=1 to comb(n,k);
call allcomb(j,k,of a[*]);
do i = 1 to k;
if i=1 then do; my_string="";counter=0;end;
counter=counter+1;
my_string=cat(compress(my_string),compress(a[i]));
if counter=k then output;
end;
end;
end;
run;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)