Generates all permutations of the values of several variables
Category: Mathematical
CALL ALLPERM ( k , variable-1 <, variable-2, ... >);
k
specifies an integer value that ranges from one to the number of permutations.
variable
specifies all numeric variables or all character variables that have the same length. The values of these variables are permuted.
Requirement: Initialize these variables before you call the ALLPERM routine.
Restriction: Specify no more than 18 variables.
Use the CALL ALLPERM routine in a loop where the first argument accepts each integral value from one to the number of permutations. On the first call, the argument types and lengths are checked for consistency. On each subsequent call, the values of two of the variables are interchanged. Because each permutation is generated from the previous permutation by a single interchange, the algorithm is very efficient.
Note: You can compute the number of permutations by using the FACT function. See 'FACT Function' on page 517 for more information.
If you use the CALL ALLPERM routine and the first argument is out of sequence, the results are not useful.
In particular, if you initialize the variables and then immediately call the ALLPERM routine with a first argument of k , for example, your result will not be the k th permutation (except when k is one). To get the k th permutation, you must call the ALLPERM routine k times, with the first argument having values from 1 through k in that exact order.
The following example generates permutations of given values by using the CALL ALLPERM routine.
data _null_; array x [4] ('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;
The following lines are written to the SAS log:
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
CALL Routines:
'CALL RANPERK Routine' on page 375
'CALL RANPERM Routine' on page 376