proc sql noprint;
create table bds as
select ads.x, ads_copy.x as y
from ads, ads ads_copy
where ads.x<ads_copy.x;
quit;
[/code:lypjddp8]
问题是如果n很大,例如n=100,我们要求出其中80个的组合
且考虑顺序,该如何求(sql最大能连接32张表,矩阵循环要做80次?)?
恳请各位sasor,指点一下。作者: shiyiming 时间: 2012-6-22 14:58 标题: Re: 如何求n个观测的组合? [code:3j6d41pr]data bds;
set ads;
do p=_n_+1 to n;
set ads(rename=(x=y)) nobs=n point=p;
output;
end;
run;[/code:3j6d41pr]作者: shiyiming 时间: 2012-7-6 15:12 标题: Re: 如何求n个观测的组合? Merlin的意思应该是,C(100 80),100个值取80个值的组合方案吧?~
hopewell大大给出的是等价于sql笛卡尔乘积组合的data step方法,是 C(n 2) 的,如果是C(100 80),也需要内嵌80个循环吗?作者: shiyiming 时间: 2012-7-10 03:34 标题: Re: 如何求n个观测的组合? C(100, 80)==5.3598337E20
Are you sure you want all of them
nevertheless, you can use ALLCOMB() function in SAS to enumerate all combinations, up to COMB(100, 80);
here is a sample code from SAS Doc
[code:2z8wl18r]
data _null_;
array x[5] $3 ('ant' 'bee' 'cat' 'dog' 'ewe');
n=dim(x);
k=3;
ncomb=comb(n,k);
do j=1 to ncomb+1;
rc=allcomb(j, k, of x[*]);
put j 5. +3 x1-x3 +3 rc=;
end;
run;
[/code:2z8wl18r]