Created
June 15, 2018 02:56
-
-
Save statgeek/894d104c129db306595e35c6bcb30da1 to your computer and use it in GitHub Desktop.
SAS - Combinations - Using LEXCOMBI to generate unique combination lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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