<?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: Determine all unique permutations of all possible treatments in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331602#M17512</link>
    <description>use uniqueby or iterate through lexperm instead of allperm</description>
    <pubDate>Fri, 10 Feb 2017 17:25:55 GMT</pubDate>
    <dc:creator>FriedEgg</dc:creator>
    <dc:date>2017-02-10T17:25:55Z</dc:date>
    <item>
      <title>Determine all unique permutations of all possible treatments</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331594#M17510</link>
      <description>&lt;P&gt;I am using SAS 9.3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am interested in generating a dataset containing all possible permutations of 3 drugs in a block size of 6, with equal numbers of each trial (1:1:1). &amp;nbsp;That is, if the treatments are A, B, C and I have a block size of 6 with 2 As, 2 Bs and 2 Cs, then some possible blocks include the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AABBCC&lt;/P&gt;
&lt;P&gt;AACCBB&lt;/P&gt;
&lt;P&gt;ABACCB&lt;/P&gt;
&lt;P&gt;AABCCB&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The important thing is that I must&amp;nbsp;have each treatment repeating twice and only twice per block. Because each treatment must be present twice in each block--this is usually where I have been running into problems with other code that i have tried. &amp;nbsp;I have unsucessfuly tried to generate this in IML and PROC PLAN (using the TREATMENTS statement). &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried to implement a process in IML, which is great, but it provides duplicates when I only want to see the unique permutations. &amp;nbsp;Here is that code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
call randseed(1234);
tName = "Treat1":"Treat6";
perms = allperm({A A B B C C}); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be appreciated!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 16:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331594#M17510</guid>
      <dc:creator>Soula</dc:creator>
      <dc:date>2017-02-10T16:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Determine all unique permutations of all possible treatments</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331602#M17512</link>
      <description>use uniqueby or iterate through lexperm instead of allperm</description>
      <pubDate>Fri, 10 Feb 2017 17:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331602#M17512</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2017-02-10T17:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Determine all unique permutations of all possible treatments</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331609#M17513</link>
      <description>&lt;P&gt;I think you an use PROC PLAN for this, but since you asked about PROC IML....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use indices 1:6 to generate the permutations and then attach whatever labels you want to tose permutations.&amp;nbsp; The resulting sets might not be unique, but maybe that is your intention?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;levels = {A A B B C C};
perms = allperm(1:6); 
plan = shape(levels[perms], 0, ncol(level));

print (perms[1:5,])  (plan[1:5,]) ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2017 17:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331609#M17513</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-02-10T17:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Determine all unique permutations of all possible treatments</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331610#M17514</link>
      <description>&lt;P&gt;There is likely to be a better way to do this with PROC PLAN too, just as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;showed with IML&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ods output plan=plan(drop=rep);
proc plan seed=1234;
factors rep=%sysfunc(fact(6)) col=6;
run;

data plan;
set plan;
array col [6];
array i   [6] _temporary_ (2*(1:3));

do _n_=1 to 6;
col[_n_]=i[col[_n_]];
end;
run;

proc sort data=plan nodupkey;
by col:;
run;

proc iml;
perm = allperm({1 1 2 2 3 3});
cols = 1:6;
call sortndx(ndx, perm, cols);
uidx = uniqueby(perm, cols, ndx);
uval = perm[ndx[uidx], cols];
create planIml from uval;
append from uval;
close planIml;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2017 18:03:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331610#M17514</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2017-02-10T18:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: Determine all unique permutations of all possible treatments</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331618#M17515</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19924"&gt;@FriedEgg&lt;/a&gt; wrote:&lt;BR /&gt;use uniqueby or iterate through lexperm instead of allperm&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is this what you had in mind and does it work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lexperm;
   array _l[6] $ ('A' 'A' 'B' 'B' 'C' 'C');
   do i = 1 by 1;
      if i gt 1 then do;
         rc=lexperm(6,of _l[*]);
         if rc lt 0 then stop;
         end;
      output;
      *put i 5. rc 2. @20 _l[*];
      end;
   run;
proc sort;
   by _L:;
   run;
proc print;
   run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2017 18:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331618#M17515</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-02-10T18:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Determine all unique permutations of all possible treatments</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331622#M17517</link>
      <description>&lt;P&gt;Yes, and yes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can be simplified to the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lexperm;
array i[6] $ 1 (2*('A' 'B' 'C'));
do _n_=1 to fact(dim(i));
  rc=lexperm(_n_, of i[*]);
  if rc&amp;lt;0 then leave;
  else output;
end;
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;lexperm also already outputs in order, so the proc sort shouldn't be necessary&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 18:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331622#M17517</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2017-02-10T18:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Determine all unique permutations of all possible treatments</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331676#M17518</link>
      <description>&lt;P&gt;Guess I should have looked at the documentation.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 20:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Determine-all-unique-permutations-of-all-possible-treatments/m-p/331676#M17518</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-02-10T20:41:48Z</dc:date>
    </item>
  </channel>
</rss>

