Generates all permutations of the values of several variables in a minimal change order.
| Category: | Combinatorial |
specifies an integer variable that ranges from 1 to the number of permutations.
specifies either all numeric variables, or all character variables that have the same length. The values of these variables are permuted.
| Restriction | Specify no more than 18 variables. |
| Requirement | Initialize these variables before you call the ALLPERM routine. |
data _null_;
array x [4] $3 ('ant' 'bee' 'cat' 'dog');
n=dim(x);
nfact=fact(n);
do i=1 to nfact;
call allperm(i, of x[*]);
put i 5. +2 x[*];
end;
run; 1 ant bee cat dog
2 ant bee dog cat
3 ant dog bee cat
4 dog ant bee cat
5 dog ant cat bee
6 ant dog cat bee
7 ant cat dog bee
8 ant cat bee dog
9 cat ant bee dog
10 cat ant dog bee
11 cat dog ant bee
12 dog cat ant bee
13 dog cat bee ant
14 cat dog bee ant
15 cat bee dog ant
16 cat bee ant dog
17 bee cat ant dog
18 bee cat dog ant
19 bee dog cat ant
20 dog bee cat ant
21 dog bee ant cat
22 bee dog ant cat
23 bee ant dog cat
24 bee ant cat dog%macro test;
%let x1=ant;
%let x2=-.1234;
%let x3=1e10;
%let x4=hippopotamus;
%let nperm=%sysfunc(perm(4));
%do j=1 %to &nperm+1;
%syscall allperm(j, x1, x2, x3, x4);
%let jfmt=%qsysfunc(putn(&j,5.));
%put &jfmt: &x1 &x2 &x3 &x4 sysinfo=&sysinfo;
%end;
%mend;
%test; 1: ant -0.1234 10000000000 hippopotamus sysinfo=0
2: ant -0.1234 hippopotamus 10000000000 sysinfo=3
3: ant hippopotamus -0.1234 10000000000 sysinfo=2
4: hippopotamus ant -0.1234 10000000000 sysinfo=1
5: hippopotamus ant 10000000000 -0.1234 sysinfo=3
6: ant hippopotamus 10000000000 -0.1234 sysinfo=1
7: ant 10000000000 hippopotamus -0.1234 sysinfo=2
8: ant 10000000000 -0.1234 hippopotamus sysinfo=3
9: 10000000000 ant -0.1234 hippopotamus sysinfo=1
10: 10000000000 ant hippopotamus -0.1234 sysinfo=3
11: 10000000000 hippopotamus ant -0.1234 sysinfo=2
12: hippopotamus 10000000000 ant -0.1234 sysinfo=1
13: hippopotamus 10000000000 -0.1234 ant sysinfo=3
14: 10000000000 hippopotamus -0.1234 ant sysinfo=1
15: 10000000000 -0.1234 hippopotamus ant sysinfo=2
16: 10000000000 -0.1234 ant hippopotamus sysinfo=3
17: -0.1234 10000000000 ant hippopotamus sysinfo=1
18: -0.1234 10000000000 hippopotamus ant sysinfo=3
19: -0.1234 hippopotamus 10000000000 ant sysinfo=2
20: hippopotamus -0.1234 10000000000 ant sysinfo=1
21: hippopotamus -0.1234 ant 10000000000 sysinfo=3
22: -0.1234 hippopotamus ant 10000000000 sysinfo=1
23: -0.1234 ant hippopotamus 10000000000 sysinfo=2
24: -0.1234 ant 10000000000 hippopotamus sysinfo=3
25: -0.1234 ant 10000000000 hippopotamus sysinfo=-1