Generates all distinct combinations of the nonmissing values of n variables taken k at a time in lexicographic order.
Category: | Combinatorial |
Interaction: | When invoked by the %SYSCALL macro statement, CALL LEXCOMB removes the quotation marks from its arguments. For more information, see Using CALL Routines and the %SYSCALL Macro Statement. |
specifies an integer value that is assigned values from 1 to the number of combinations in a loop.
specifies an integer constant, variable, or expression between 1 and n, inclusive, that specifies the number of items in each combination.
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 call the LEXCOMB routine. |
Tip | After calling LEXCOMB, the first k variables contain the values in one combination. |
%macro test; %let x1=ant; %let x2=baboon; %let x3=baboon; %let x4=hippopotamus; %let x5=zebra; %let k=2; %let ncomb=%sysfunc(comb(5,&k)); %do j=1 %to &ncomb; %syscall lexcomb(j, k, x1, x2, x3, x4, x5); %let jfmt=%qsysfunc(putn(&j, 5. )); %let pad=%qsysfunc(repeat(%str( ), 20-%length(&x1 &x2))); %put &jfmt: &x1 &x2 &pad sysinfo=&sysinfo; %if &sysinfo < 0 %then %let j=%eval(&ncomb+1); %end; %mend; %test