Generates all combinations of the values of n variables taken k at a time in a minimal change order.

Category: | Combinatorial |

specifies an integer variable that is assigned 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.

Restriction | Specify no more than 33 items. If you need to find combinations of more than 33 items, use the CALL ALLCOMBI routine. |

Requirement | Initialize these variables before calling the ALLCOMB routine. |

Tip | After calling the ALLCOMB routine, the first k variables contain the values in one combination. |

Use the CALL ALLCOMB
routine in a loop where the first argument to CALL ALLCOMB accepts
each integral value from 1 to the number of combinations, and where k is constant. The number of combinations can
be computed by using the COMB function. On the first call, the argument
types and lengths are checked for consistency. On each subsequent
call, the values of two variables are interchanged.

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

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

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

%macro test; %let x1=ant; %let x2=-.1234; %let x3=1e10; %let x4=hippopotamus; %let x5=zebra; %let k=2; %let ncomb=%sysfunc(comb(5,&k)); %do j=1 %to &ncomb+1; %syscall allcomb(j, k, x1, x2, x3, x4, x5); %let jfmt=%qsysfunc(putn(&j,5.)); %let pad=%qsysfunc(repeat(%str(),30-%length(&x1 &x2))); %put &jfmt: &x1 &x2 &pad sysinfo=&sysinfo; %end; %mend; %test

SAS writes the following
output to the log:

1: ant -0.1234 sysinfo=0 2: ant zebra sysinfo=2 3: ant hippopotamus sysinfo=2 4: ant 10000000000 sysinfo=2 5: -0.1234 10000000000 sysinfo=1 6: -0.1234 zebra sysinfo=2 7: -0.1234 hippopotamus sysinfo=2 8: 10000000000 hippopotamus sysinfo=1 9: 10000000000 zebra sysinfo=2 10: hippopotamus zebra sysinfo=1 11: hippopotamus zebra sysinfo=-1

Copyright © SAS Institute Inc. All rights reserved.