<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Combinatorial problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675536#M203563</link>
    <description>&lt;P&gt;Is randomness really required in the first step? If, at the end, "each person has seen all of the other 14 people exactly once"?&lt;/P&gt;</description>
    <pubDate>Mon, 10 Aug 2020 05:58:50 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-08-10T05:58:50Z</dc:date>
    <item>
      <title>Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675498#M203554</link>
      <description>&lt;P&gt;I'm hoping someone can help me with this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To start, I have 15 people, and I want to assign them randomly to groups of 3. No problem, I know how to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The real problem is that I want to randomly assign each person to a second group of 3 with the restriction that none of my 15 people see the same individual in the second group of three as they saw in the first group of three. And then continue, assign each person randomly to a 3rd group of three, such that no person still has seen another person more than once. And so on, until each person is assigned to a 7th group such that each person has seen all of the other 14 people exactly once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone point me in the right direction?&lt;/P&gt;</description>
      <pubDate>Sun, 09 Aug 2020 19:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675498#M203554</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-09T19:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675507#M203556</link>
      <description>&lt;P&gt;Now that's one to think about.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Aug 2020 21:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675507#M203556</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-09T21:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675526#M203561</link>
      <description>&lt;P&gt;Not sure this will help, but it's food for thought.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would it help to create all 105 unique pairs, and use that as a starting point?&amp;nbsp; For example:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;randomly select which pairs to use (and remove those from the list of 105)&lt;/LI&gt;
&lt;LI&gt;randomly select which third ID to add to each pair, taking care not to use anyone twice&lt;/LI&gt;
&lt;LI&gt;repeat for the remaining 90 pairs&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I'm not sure how to do all this but if it's a valid approach it may simplify things a bit.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 01:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675526#M203561</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-08-10T01:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675536#M203563</link>
      <description>&lt;P&gt;Is randomness really required in the first step? If, at the end, "each person has seen all of the other 14 people exactly once"?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 05:58:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675536#M203563</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-10T05:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675552#M203569</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is randomness really required in the first step? If, at the end, "each person has seen all of the other 14 people exactly once"?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are correct! Randomness is not required at all.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 10:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675552#M203569</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-10T10:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675581#M203573</link>
      <description>&lt;P&gt;Next code creates 35 records each with 3 numbers in the range of 1 to 15.&lt;/P&gt;
&lt;P&gt;I am not sure that in some cases it will not create duplicates.&lt;/P&gt;
&lt;P&gt;Any how I ran it without dups.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675498
*/

data g3;
     array tx {15} t1-t15;   /* temporary */
     array sx {15} s1-s15;   /* sorted */
     array vx {105} v1-v105; /* 7 groups * 5 3rds * 3 digits */
    
    /* initiate */
    do i=1 to 15; vx(i) = i; end;
    
    /* add 6 groups of 3*5 */
    do j=1 to 6;  
       link init_tx;
       link select_rand; /* new random order of 1-15 */
       link apnd15_2vx;
       
    end;
    
    /* output in group of 3 */
    do i=1 to 105 by 3;
       if vx(i) = . then leave;
       comb = catx(',',put(vx(i),2.),put(vx(i+1),2.),put(vx(i+2),2.));
       keep i comb;
       output;
    end;
    
return;
*==========;
INIT_TX:
   do i=1 to 15; tx(i) = .; end;
return;
*==========;
SELECT_RAND:
   do i=1 to 15;
      flag=0;
      do until (flag=1);
          n = round(15*ranuni(0),1.); if n=0 then n+1;
          if not (whichn(n,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15)) &amp;gt; 0 then do;
             flag=1; tx(i) = n;
          end; 
      end;
   end;
return;
*==========;
APND15_2VX:
   do i=1 to 15;
      vx(j*15+i) = tx(i);
   end;
return;
*==========;

run;

proc sort data=g3 out=g3s nodupkey ; by comb; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 13:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675581#M203573</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-10T13:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675625#M203583</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found one particular solution in&lt;/P&gt;
&lt;P&gt;D.R. Cox, N. Reid (2000): &lt;EM&gt;The Theory of the Design of Experiments.&lt;/EM&gt;&amp;nbsp;Boca Raton: Chapman &amp;amp; Hall/CRC (see Table 4.4, p. 73).&lt;/P&gt;
&lt;P&gt;It's an example of an incomplete block design. Many (if not all) other solutions could be derived from this by permuting the 15 IDs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The page happens to be available via Google book search:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://books.google.de/books?id=a_vKBQAAQBAJ&amp;amp;pg=PA72&amp;amp;dq=%22Two+special+incomplete+block+designs%22&amp;amp;hl=de&amp;amp;sa=X&amp;amp;ved=2ahUKEwi32Yek9ZDrAhXMzqQKHZuYDogQuwUwAHoECAAQCg#v=onepage&amp;amp;q=%22Two%20special%20incomplete%20block%20designs%22&amp;amp;f=false" target="_self"&gt;https://books.google.de/books?id=a_vKBQAAQBAJ&amp;amp;pg=PA72&amp;amp;dq=%22Two+special+incomplete+block+designs%22&amp;amp;hl=de&amp;amp;sa=X&amp;amp;ved=2ahUKEwi32Yek9ZDrAhXMzqQKHZuYDogQuwUwAHoECAAQCg#v=onepage&amp;amp;q=%22Two%20special%20incomplete%20block%20designs%22&amp;amp;f=false&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that there's a typo in row IV, column four: The "4" must read "14"!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 15:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675625#M203583</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-08-10T15:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675682#M203598</link>
      <description>&lt;P&gt;If randomness is not required, here is a (relatively) simple way to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, some test data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data persons;
  do _N_=1 to 15;
    ID=213*_N_+33;
    output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then generate all possible ordered triples of numbers from 1 to 15:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
  do P1=1 to 13;
    do P2=P1+1 to 14;
      do P3=P2+1 to 15;
        output;
        end;
      end;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, create an empty table to hold the pairs that have already been used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data used;
  length _P1 _P2 8;
  stop;
run;

proc sql;
  create index idx on used(_P1,_P2);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And showtime! Create a list of 35 usable triples in table TRIPLES:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data triples(keep=P1 P2 P3) used;
  found=1;
  set all;
  _P1=P1;
  _P2=P2;
  link check;
  _P2=P3;
  link check;
  _P1=P2;
  link check;
  if found then do;
    output triples;
    _P1=P1;
    _P2=P2;
    output used;
    _P2=P3;
    output used;
    _P1=P2;
    output used;
    end;
  _error_=0;
  return;
  check:
    modify used key=idx;
    if _iorc_=0 then /* key was found, meaning pair has already been used */
      found=0;
    return;     
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, get the actual person data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set triples;
  set persons(rename=(ID=ID1)) point=P1;
  set persons(rename=(ID=ID2)) point=P2;
  set persons(rename=(ID=ID3)) point=P3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you do want random after all, you can sort the table PERSONS in random order before creating WANT. But do not sort ALL, that breaks the program.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 17:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675682#M203598</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-08-10T17:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675724#M203613</link>
      <description>&lt;P&gt;Incomplete block designs ... why didn't I think of that?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 19:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675724#M203613</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-10T19:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675730#M203617</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt; this is brilliant, and I will have to study the code to be sure I understand it properly, but it does seem to work. Thanks! I could only mark one answer correct, and so the first one offered is the one I marked correct.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 19:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675730#M203617</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-10T19:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675741#M203621</link>
      <description>&lt;P&gt;Okay, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt; and others&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's one more problem that isn't solved, and where the analogy to incomplete block designs breaks down. I have to schedule the 15 people into groups of 3 over 7 different time periods. The solutions presented so far provide the groups, such that no person is in the same group as any other person twice (or more). But how do I split these groups into 7 time periods now such that each of the 7 time periods has 5 of the groups and no person appears in a time period more than once?? How do I create a schedule, because as you know, a person cannot be in two groups at once.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 20:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675741#M203621</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-10T20:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675780#M203638</link>
      <description>&lt;P&gt;I was able to use "brute force" to search for 5 groups of 3, repeating for 7 weeks, with no person seeing another person more than once, from the code provided above by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt; . If there are smarter ways to do this that don't involve "brute force" searching through all possible combinations of groups, please let me know.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 22:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675780#M203638</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-10T22:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675887#M203697</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Okay, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt; and others&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's one more problem that isn't solved, and where the analogy to incomplete block designs breaks down. I have to schedule the 15 people into groups of 3 over 7 different time periods. The solutions presented so far provide the groups, such that no person is in the same group as any other person twice (or more). But how do I split these groups into 7 time periods now such that each of the 7 time periods has 5 of the groups and no person appears in a time period more than once?? How do I create a schedule, because as you know, a person cannot be in two groups at once.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure if I understand the issue correctly. The book solution (with the typo corrected) does satisfy the condition that each of the 7 "time periods" (numbered I, II, III, ..., VII) contains each of the 15 "persons" exactly once (in addition to the criterion about persons meeting only once in a group). What is the new criterion that is not yet satisfied?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 12:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675887#M203697</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-08-11T12:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675895#M203704</link>
      <description>&lt;P&gt;In an incomplete block design, I can have treatments 1, 2 and 3 in a group, and the very next group can be treatments 1,4,5, and so on, until all blocks are assigned and then the test can all be run at one time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With people, I cannot have 1,2,3 together at the same time as I have 1,4,5 together. 1,2,3 has to be at a given time period, say time 1, and 1,4,5 cannot happen at time 1, it must happen at time 2 or later. So I must assign 5 groups at time 1, and another 5 groups at time 2, with the restriction that no individual gets assigned more than one time at a given time period.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 12:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675895#M203704</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-11T12:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675905#M203713</link>
      <description>&lt;P&gt;Sure. But, again, in the particular solution from the book I don't see such a conflict where one person (i.e., number 1, ..., 15) occurs twice in the same time period (i.e., row I, II, ..., VII).&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 12:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675905#M203713</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-08-11T12:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Combinatorial problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675911#M203717</link>
      <description>&lt;P&gt;Okay, I see your point. Obviously, the book has the answer. I was working from the code provided by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt; which doesn't quite perform this last step. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 13:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinatorial-problem/m-p/675911#M203717</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-11T13:30:07Z</dc:date>
    </item>
  </channel>
</rss>

