| Functions and CALL Routines |
| Category: | Mathematical |
| Syntax | |
| Arguments | |
| Details | |
| Examples | |
| See Also |
Syntax |
| CALL ALLPERM(k, variable-1<, variable-2, ...>); |
specifies an integer value that ranges from one to the number of permutations.
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. |
| Details |
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 for more information. ![[cautionend]](../common.hlp/images/cautend.gif)
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 kth permutation (except when k is one). To get the kth permutation, you must call the ALLPERM routine k times, with the first argument having values from 1 through k in that exact order.
| Examples |
The following example generates permutations of given values by using the CALL 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;
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
| See Also |
|
CALL Routines: |
Copyright © 2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.