Generates all distinct permutations of the non-missing values of n variables taken k at a time in lexicographic order.
Category: | Combinatorial |
Restriction: | The LEXPERK function cannot be executed when you use the %SYSFUNC macro. |
specifies an integer variable that ranges from 1 to the number of permutations.
is a numeric constant, variable, or expression with an integer value between 1 and n inclusive.
specifies either 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 execute the LEXPERK function. |
Tip | After executing LEXPERK, the first k variables contain the values in one permutation. |
data _null_; array x[5] $3 ('X' 'Y' 'Z' 'Z' 'Y'); n=dim(x); k=3; nperm=perm(n,k); do j=1 to nperm+1; rc=lexperk(j, k, of x[*]); put j 5. +3 x1-x3 +3 rc=; if rc<0 then leave; end; run;
1 X Y Y rc=1 2 X Y Z rc=3 3 X Z Y rc=2 4 X Z Z rc=3 5 Y X Y rc=1 6 Y X Z rc=3 7 Y Y X rc=2 8 Y Y Z rc=3 9 Y Z X rc=2 10 Y Z Y rc=3 11 Y Z Z rc=3 12 Z X Y rc=1 13 Z X Z rc=3 14 Z Y X rc=2 15 Z Y Y rc=3 16 Z Y Z rc=3 17 Z Z X rc=2 18 Z Z Y rc=3 19 Z Z Y rc=-1