<?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: Proc IML loops, combinations and merges in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392890#M3711</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12982"&gt;@ilikesas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
               
do k = 1 to 3;  
combk = allcomb(5, k);                    
print combk;
end;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in order to get all the possible 1,2 and 3 number combinations of the values 1 to 5. I would like to have the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Have the names of the generated tables/matrices be comb1, comb2 and comb3 (right now they are all combk).&lt;/P&gt;
&lt;P&gt;2) Merge the 3 tables/matrices into one single table/matrix&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do it in a data step instead of PROC IML. Eliminate the requirement #1, just save the value of the loop variable, and you've got your final data table.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Sep 2017 01:15:44 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-09-04T01:15:44Z</dc:date>
    <item>
      <title>Proc IML loops, combinations and merges</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392886#M3710</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
               
do k = 1 to 3;  
combk = allcomb(5, k);                    
print combk;
end;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in order to get all the possible 1,2 and 3 number combinations of the values 1 to 5. I would like to have the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Have the names of the generated tables/matrices be comb1, comb2 and comb3 (right now they are all combk).&lt;/P&gt;
&lt;P&gt;2) Merge the 3 tables/matrices into one single table/matrix&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2017 01:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392886#M3710</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-09-04T01:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML loops, combinations and merges</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392890#M3711</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12982"&gt;@ilikesas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
               
do k = 1 to 3;  
combk = allcomb(5, k);                    
print combk;
end;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in order to get all the possible 1,2 and 3 number combinations of the values 1 to 5. I would like to have the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Have the names of the generated tables/matrices be comb1, comb2 and comb3 (right now they are all combk).&lt;/P&gt;
&lt;P&gt;2) Merge the 3 tables/matrices into one single table/matrix&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do it in a data step instead of PROC IML. Eliminate the requirement #1, just save the value of the loop variable, and you've got your final data table.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2017 01:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392890#M3711</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-04T01:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML loops, combinations and merges</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392893#M3712</link>
      <description>&lt;P&gt;Hi PaigeMiller,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to do the following code using the Data Step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   array x[5] $3 ('ant' 'bee' 'cat' 'dog' 'ewe');
   n=dim(x);
 do k= 1 to 3;
   ncomb=comb(n,k);
   do j = 1 to ncomb;
      call allcomb(k, 5, of x[*]);
     output;
  end;
end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This calculated the number of combinations for each k given the array of 5 items, but didn't generate the actual combination???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2017 01:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392893#M3712</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-09-04T01:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML loops, combinations and merges</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392939#M3713</link>
      <description>&lt;P&gt;The call to allcomb is incorrect as it is always requesting a subset of size 5, also the 1st parameter should be j rather than k.&amp;nbsp; The following code should work -&amp;nbsp;I am generating numbers rather than&amp;nbsp;animals and I have also transferred the combinations to the array y, in order to get missing values&amp;nbsp;values where the subset is&amp;nbsp;less than&amp;nbsp;the maximum size.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   array x[5] _temporary_ (1:5) ;
   array y[3] ;
   n = dim(x);
   do k = 1 to 3;
     ncomb = comb(n,k);
     do j = 1 to ncomb;
        call allcomb(j, k, of x[*]);
		do i = 1 to k;
		  y[i] = x[i];
		end;
	    output;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Sep 2017 07:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392939#M3713</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2017-09-04T07:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML loops, combinations and merges</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392978#M3714</link>
      <description>&lt;P&gt;I would imagine that if you're going to follow the example in the documentation, you shouldn't be adding in steps and code that isn't in the example. You shouldn't be adding in&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; do k&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003112305.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003112305.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, you need to explain further:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;but didn't generate the actual combination&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does it do? What is the error in the log?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2017 11:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/392978#M3714</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-04T11:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML loops, combinations and merges</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/393013#M3715</link>
      <description>&lt;P&gt;Expandgrid() is what you are looking for ?&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;
x=1:5;
want=expandgrid(x,0,0)//expandgrid(x,x,0)//expandgrid(x,x,x);
print want;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Sep 2017 15:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/393013#M3715</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-09-04T15:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML loops, combinations and merges</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/393032#M3716</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;get an error message: invocation of unresolved module EXPANDGRID&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2017 18:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/393032#M3716</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-09-04T18:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML loops, combinations and merges</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/393107#M3717</link>
      <description>&lt;P&gt;You must have an old version of IML that does not have EXPANDGRID, in any case it will give permutations rather than combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you prefer an IML solution, then your original idea of a loop over the allcomb function is sound, the tricky part of the problem is working out how many combinations of each size there are, and where to place them in the final matrix c.&amp;nbsp; Here is my suggestion for achieving this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
  n = 5;
  maxk = 3;
  nc = comb( n, 1:maxk );   /* ncomb for each size k     */
  c = j(sum(nc), maxk, .);  /* matrix to hold everything */
  r2 = cusum( nc );         /* last row in c of size k   */
  r1 = r2 - nc + 1;         /* first row in c of size k  */
  do k = 1 to maxk;         /* fill c with combinations  */
    c [ r1[k]:r2[k], 1:k] = allcomb(n, k);
  end;
  print c;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Sep 2017 07:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/393107#M3717</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2017-09-05T07:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML loops, combinations and merges</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/393233#M3718</link>
      <description>&lt;PRE&gt;
OK. How about this one ?

proc iml;
              
do k = 1 to 3; 
 x='comb'+strip(char(k)); 
 call valset(x,allcomb(5, k));   
end;
print comb1 ,comb2 ,comb3;

want=(comb1||repeat(0,nrow(comb1),2)) //
     (comb2||repeat(0,nrow(comb2),1)) //
	 comb3;
print want;

quit;


&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Sep 2017 14:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/393233#M3718</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-09-05T14:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML loops, combinations and merges</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/393414#M3721</link>
      <description>&lt;P&gt;Hi KSharp, still not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Get the first error message right after the&amp;nbsp;x='comb'+strip(char(k)); &amp;nbsp;saying that the matrix has not been set to a value&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 02:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-loops-combinations-and-merges/m-p/393414#M3721</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-09-06T02:11:43Z</dc:date>
    </item>
  </channel>
</rss>

