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. |

When all of the variables
have nonmissing, unequal values, then the number of combinations is
COMB(n,k). If the number of variables that have missing values is m, and all the nonmissing values are unequal,
then LEXCOMB produces COMB(n-m,k) combinations because the missing values are omitted from the combinations.

On subsequent calls,
up to and including the last combination, the next distinct combination
of the nonmissing values is generated in lexicographic order.

If you call the LEXCOMB
routine with the first argument out of sequence, then the results
are not useful. In particular, if you initialize the variables and
then immediately call the LEXCOMB routine with a first argument of j, you will not get the j^{th} combination (except when j is 1). To get the j^{th} combination, you must call the LEXCOMB
routine j times, with the
first argument taking values from 1 through j in that exact order.

You can call the LEXCOMB routine when you use the %SYSCALL macro.
In this case, the variable arguments
are not required to be the same length, but they are required to be
the same type. If %SYSCALL identifies an argument as numeric, then
%SYSCALL reformats the returned value.

If an error occurs during
the execution of the CALL LEXCOMB routine, then both of the following
values are set:

The following example calls the
LEXCOMB routine to generate distinct combinations in lexicographic
order.

The following is an example of the CALL LEXCOMB routine that is
used with macros. The output includes values for the %SYSINFO macro.

%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

Copyright © SAS Institute Inc. All rights reserved.