Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created June 15, 2018 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statgeek/894d104c129db306595e35c6bcb30da1 to your computer and use it in GitHub Desktop.
Save statgeek/894d104c129db306595e35c6bcb30da1 to your computer and use it in GitHub Desktop.
SAS - Combinations - Using LEXCOMBI to generate unique combination lists
/*this creates a list of combinations, designed for numeric variables*/
%let n=5; /* total number of items */
%let k=2; /* number of items per row */
/* generate combinations of n items taken k at a time */
data Comb(keep=c1-c&k);
array c[&k] (&k.*0); /* initialize array to 0 */
array list[&n] _temporary_ (1, 2, 3, 4, 5);
ncomb = comb(&n, &k); /* number of combinations */
do j = 1 to ncomb;
rc = lexcombi(&n, &k, of c[*]);
do i=1 to dim(c);
c(i)=list(c(i));
end;
output;
end;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment