複数の変数の非欠損値の重複しないすべての順列を辞書式順序で生成します。
カテゴリ: | 組み合わせ |
操作: | %SYSCALLマクロステートメントで呼び出されると、CALL LEXPERMの引数から引用符が削除されます。 詳細については、CALLルーチンと%SYSCALLマクロステートメントを使用するを参照してください。 |
data _null_; array x[4] $3 ('ant' 'bee' 'cat' 'dog'); n=dim(x); nfact=fact(n); do i=1 to nfact; call lexperm(i, of x[*]); put i 5. +2 x[*]; end; run;
1 ant bee cat dog 2 ant bee dog cat 3 ant cat bee dog 4 ant cat dog bee 5 ant dog bee cat 6 ant dog cat bee 7 bee ant cat dog 8 bee ant dog cat 9 bee cat ant dog 10 bee cat dog ant 11 bee dog ant cat 12 bee dog cat ant 13 cat ant bee dog 14 cat ant dog bee 15 cat bee ant dog 16 cat bee dog ant 17 cat dog ant bee 18 cat dog bee ant 19 dog ant bee cat 20 dog ant cat bee 21 dog bee ant cat 22 dog bee cat ant 23 dog cat ant bee 24 dog cat bee ant
%macro test; %let x1=ant; %let x2=baboon; %let x3=baboon; %let x4=hippopotamus; %let n=4; %let nperm=%sysfunc(perm(4)); %do j=1 %to &nperm; %syscall lexperm(j, x1, x2, x3, x4); %let jfmt=%qsysfunc(putn(&j, 5.)); %put &jfmt: &x1 &x2 &x3 &x4 sysinfo=&sysinfo; %if &sysinfo<0 %then %let j=%eval(&nperm+1); %end; %mend; %test;
1: ant baboon baboon hippopotamus sysinfo=1 2: ant baboon hippopotamus baboon sysinfo=3 3: ant hippopotamus baboon baboon sysinfo=2 4: baboon ant baboon hippopotamus sysinfo=1 5: baboon ant hippopotamus baboon sysinfo=3 6: baboon baboon ant hippopotamus sysinfo=2 7: baboon baboon hippopotamus ant sysinfo=3 8: baboon hippopotamus ant baboon sysinfo=2 9: baboon hippopotamus baboon ant sysinfo=3 10: hippopotamus ant baboon baboon sysinfo=1 11: hippopotamus baboon ant baboon sysinfo=2 12: hippopotamus baboon baboon ant sysinfo=3 13: hippopotamus baboon baboon ant sysinfo=-1