<?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: Generating combinations from a list of values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generating-combinations-from-a-list-of-values/m-p/375318#M89960</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
array c[3] $ ('a' 'b' 'c');
array x[3];
length comb $ 400;
n=dim(x);
k=-1;
nsubs=2**n;
do i=1 to nsubs;
 rc=graycode(k, of x[*]);
 call missing(comb);
 do j=1 to n;
  if x[j]=1 then comb=catx(' ',comb,c[j]);
 end;
 if not missing(comb) then putlog comb= ;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 12 Jul 2017 14:02:09 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-07-12T14:02:09Z</dc:date>
    <item>
      <title>Generating combinations from a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-combinations-from-a-list-of-values/m-p/374985#M89841</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given a set of values, say A B and C, I need to generate the following from it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;P&gt;B&lt;/P&gt;
&lt;P&gt;C&lt;/P&gt;
&lt;P&gt;A B&lt;/P&gt;
&lt;P&gt;A C&lt;/P&gt;
&lt;P&gt;B C&lt;/P&gt;
&lt;P&gt;A B C&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've looked at the permutation functions that those don't seem to fit. &amp;nbsp;Not sure about Proc Plan either. &amp;nbsp;Data step would be prefereable but not required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;--Ben&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 14:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-combinations-from-a-list-of-values/m-p/374985#M89841</guid>
      <dc:creator>BenConner</dc:creator>
      <dc:date>2017-07-11T14:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Generating combinations from a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-combinations-from-a-list-of-values/m-p/375017#M89865</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is the output supposed to be a data set or text output? Do you want a single variable with the "value" or something such as a series of variables that is populated with the desired pieces?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may help to indicate how you are getting the values that you need to combine. Do you have list or a data set? And how many actual values are you going to be concerned with?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This comes pretty close:&lt;/P&gt;
&lt;PRE&gt;data junk;
   array x[3] $3 ('a' 'b' 'c' );
   array h[3] $3 ;
   n=dim(x);
   do k=1 to 3;
   ncomb=comb(n, k);
      call sortc(of x(*));
      /* empty target array*/
      call missing (of h(*));
      do j=1 to ncomb;
         rc=allcomb(j, k, of x[*]);
         if rc&amp;lt;0 then leave;
         do i=1 to k;
            h[i]=x[i];
         end;
         longstr= cats(of h(*));
         output;
      end;
   end;
   drop i j k n ncomb rc;
run;&lt;/PRE&gt;
&lt;P&gt;if the want is a single variable look at the longstr, if array look at h. You may want to sort the data set if order is critical.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 15:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-combinations-from-a-list-of-values/m-p/375017#M89865</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-11T15:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Generating combinations from a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-combinations-from-a-list-of-values/m-p/375038#M89873</link>
      <description>&lt;P&gt;Actually that's perfect! &amp;nbsp;I was going to chuck the values into an array statement for the real problem and this is what I was looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;--Ben&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 16:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-combinations-from-a-list-of-values/m-p/375038#M89873</guid>
      <dc:creator>BenConner</dc:creator>
      <dc:date>2017-07-11T16:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: Generating combinations from a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-combinations-from-a-list-of-values/m-p/375318#M89960</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
array c[3] $ ('a' 'b' 'c');
array x[3];
length comb $ 400;
n=dim(x);
k=-1;
nsubs=2**n;
do i=1 to nsubs;
 rc=graycode(k, of x[*]);
 call missing(comb);
 do j=1 to n;
  if x[j]=1 then comb=catx(' ',comb,c[j]);
 end;
 if not missing(comb) then putlog comb= ;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jul 2017 14:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-combinations-from-a-list-of-values/m-p/375318#M89960</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-07-12T14:02:09Z</dc:date>
    </item>
  </channel>
</rss>

