SAS code to create game scheduler for 8 players

#1
I'm trying to set up a pseudo tournament competition thing. There are 8 players and at any given time 4 of the 8 players can participate. I would like everyone to play 12 games and everyone needs to play with everyone at least 4 times but no more than 8 times (if that range needs to be adjusted, that's fine).

So for example, if game #1 had players 1,2,3,4 that means player 1 has now played 1 game each with players 2,3,4.....player 2 has played 1 game each with players 1,3,4.....

If game #2 was player 1,2,6,7 - that means player 1 has now played 2 games with player 2 and 1 game each with players 6 and 7......

Order of the players doesn't matter (so 1 2 3 4 is the same as 4 3 2 1) and below is some code to quickly get a dataset with the list of all the 4 player combinations. Further, I don't want the combinations to simply be a product of which number the player is so I randomize the order of the games as well.

I'm struggling with how to create some sort of code that will pick the games that follow these criteria:
* everyone plays 12 games
* everyone plays with the other 7 players between 4 and 8 times



CODE TO GET LIST OF 70 COMBINATIONS
Code:
/* all possible 4 player pairings */
data team_combos;
     retain game 0;
   do i=1 to 8;
        do j=1 to 8; if j>i then do;
             do k=1 to 8; if k>j then do;
                   do l=1 to 8; if l>k then do;
                        grp=put(i,1.)||' '||put(j,1.)||' '||put(k,1.)||' '||put(l,1.);
                                game+1;
                                drop i j k l;
                        output;
                   end; end;
             end; end;
        end; end;
   end;
run;

/* create random order of games */
proc plan seed=1;
     factors order=70 random / noprint;
     output out=games_order;
run;

data games_order;
set games_order;
     row=_N_;
run;

proc sql noprint;
     create table team_combos as
           select tc.grp
                  ,tc.game
                 ,go.order
           from team_combos tc
               ,games_order go
           where tc.game = go.row
           order by go.order
;quit;

proc datasets library=work;
     delete games_order;
run;
 
Last edited: