<?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: Generate all Combinations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396720#M95808</link>
    <description>&lt;P&gt;IN THEORY, &lt;STRONG&gt;proc plan&lt;/STRONG&gt; could be used to generate all possible combinations, something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods listing select none;
proc plan;
factors 
    block = 5870592 ordered
    grai = 1 of 4 comb
    frui = 2 of 7 comb
    vege = 3 of 14 comb
    swee = 1 of 4 comb
    lean = 1 of 4 comb;
ods output plan=design;
run;
ods listing select all;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but it crashes with INTEGER OVERFLOW. It might work with a 64 bit version of SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Sep 2017 03:04:59 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-09-18T03:04:59Z</dc:date>
    <item>
      <title>Generate all Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396604#M95777</link>
      <description>&lt;P&gt;Trying to generate a list of all possible combinations using the following data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Food Group&lt;/TD&gt;&lt;TD&gt;Name&lt;/TD&gt;&lt;TD&gt;Points&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Grains&lt;/TD&gt;&lt;TD&gt;Brown Rice&lt;/TD&gt;&lt;TD&gt;2&l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;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vegetables/Legumes&lt;/TD&gt;&lt;TD&gt;Squash&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vegetables/Legumes&lt;/TD&gt;&lt;TD&gt;Eggplant&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vegetables/Legumes&lt;/TD&gt;&lt;TD&gt;Kale&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vegetables/Legumes&lt;/TD&gt;&lt;TD&gt;Red Cabbage&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vegetables/Legumes&lt;/TD&gt;&lt;TD&gt;Asparagus&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vegetables/Legumes&lt;/TD&gt;&lt;TD&gt;Sweet Potato&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vegetables/Legumes&lt;/TD&gt;&lt;TD&gt;White Potato&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vegetables/Legumes&lt;/TD&gt;&lt;TD&gt;Corn on Cob&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vegetables/Legumes&lt;/TD&gt;&lt;TD&gt;Red Lentils&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vegetables/Legumes&lt;/TD&gt;&lt;TD&gt;Tomato&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;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&gt;Fried Fish&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My exercise is to generate all of the combinations where I have 1 Grain, 2 Fruit, 3 Vegetables, 1 Sweet, 1 Lean Meat where total points is less than or equal to 25.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not have access to PROC IML.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2017 00:18:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396604#M95777</guid>
      <dc:creator>crawdaddy</dc:creator>
      <dc:date>2017-09-17T00:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Generate all Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396615#M95782</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/165543"&gt;@crawdaddy&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;As this is an excercise we possibly shouldn't just give you the full solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What solution approaches have you considered and what have you tried already?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2017 01:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396615#M95782</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-17T01:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: Generate all Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396619#M95785</link>
      <description>&lt;P&gt;And you are probably being asked to produce total points for each qualifying combination, yes?&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2017 02:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396619#M95785</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-17T02:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: Generate all Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396648#M95796</link>
      <description>&lt;PRE&gt;
I is more like a OR problem .
Better posted it at OR forum @RobPratt is there .
If you have SAS/IML, maybe I could write some Genetic Algorithm for you .



&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Sep 2017 11:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396648#M95796</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-09-17T11:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Generate all Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396661#M95803</link>
      <description>&lt;P&gt;Without getting in into how to do this in SAS, ... as a strategy how about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Make 5 datasets, one per group
&lt;OL&gt;
&lt;LI&gt;Vegetable dataset: All 3-element combinations of Vegetables&lt;/LI&gt;
&lt;LI&gt;Fruits: All 2-element combinations of Fruits&lt;/LI&gt;
&lt;LI&gt;etc. etc.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;Do a full cartesian crossing of the 5 datasets.&lt;/LI&gt;
&lt;/OL&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>Sun, 17 Sep 2017 16:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396661#M95803</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-17T16:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: Generate all Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396720#M95808</link>
      <description>&lt;P&gt;IN THEORY, &lt;STRONG&gt;proc plan&lt;/STRONG&gt; could be used to generate all possible combinations, something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods listing select none;
proc plan;
factors 
    block = 5870592 ordered
    grai = 1 of 4 comb
    frui = 2 of 7 comb
    vege = 3 of 14 comb
    swee = 1 of 4 comb
    lean = 1 of 4 comb;
ods output plan=design;
run;
ods listing select all;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but it crashes with INTEGER OVERFLOW. It might work with a 64 bit version of SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 03:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396720#M95808</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-09-18T03:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: Generate all Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396825#M95843</link>
      <description>&lt;P&gt;When you say &amp;nbsp;2 Fruit, 3 Vegetables must the 2 fruits be unique or are they allowed to duplicate, same for the vegetables?&lt;/P&gt;
&lt;P&gt;Must all groups be represented&amp;nbsp;with that exact&amp;nbsp;count of items?&lt;/P&gt;
&lt;P&gt;Is the list of items shown exhaustive, meaning there are no other grains, fruits etc. in the actual problem other than those shown?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what should the output actually look like? I can think of one approach involving nested do loops that would work but may not provide the prettiest output.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 14:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396825#M95843</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-18T14:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Generate all Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396887#M95871</link>
      <description>&lt;P&gt;Yes, this was exactly what I needed in order to generate all of the combinations. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This was the start I needed to get the ball rolling. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have additional rules I need to account for, however I think I'll be able to handle those myself.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 17:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/396887#M95871</guid>
      <dc:creator>crawdaddy</dc:creator>
      <dc:date>2017-09-18T17:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Generate all Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/397055#M95931</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/165543"&gt;@crawdaddy&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;To create first all the combination and then to filter the result is the standard way of doing this. The downside of such an approach is that you can end up with a huge amount of combinations and a very big intermediary table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know in advance that you don't need to test all combinations, i.e. that for vegetables A B C is the same like B A C or C B A and that you only need to test one of these combinations then the sequential processing of the SAS data step offers often alternative design approaches allowing you to only create and test the combinations you really need.&lt;/P&gt;
&lt;P&gt;Such an approach can significantly outperform anything that relies on creating all possible combinations (execute below sample code and you'll see).&lt;/P&gt;
&lt;P&gt;The disadvantage of such a data step approach can be quite complex code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below an example how this could look like using SAS Datastep coding.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dlm='|' dsd;
  input Food:$40. Group_Name:$20. Points;
datalines;
Grains|Brown Rice|2
Grains|Quinoa|2
Grains|White Rice|3
Grains|English Muffin|4
Fruits|Watermelon|3
Fruits|Apple|2
Fruits|Peach|1
Fruits|Grapes|4
Fruits|Canned Fruit|4
Fruits|Pear|1
Fruits|Mango|2
Vegetables/Legumes|Iceberg Lettuce|2
Vegetables/Legumes|Squash|2
Vegetables/Legumes|Eggplant|1
Vegetables/Legumes|Kale|3
Vegetables/Legumes|Red Cabbage|4
Vegetables/Legumes|Asparagus|3
Vegetables/Legumes|Sweet Potato|2
Vegetables/Legumes|White Potato|1
Vegetables/Legumes|Corn on Cob|1
Vegetables/Legumes|Red Lentils|4
Vegetables/Legumes|Tomato|2
Vegetables/Legumes|Bok Choy|3
Vegetables/Legumes|Frozen Vegetables|1
Vegetables/Legumes|Red Onion|2
Sweets|Ice Cream|1
Sweets|Pudding|1
Sweets|Dark Chocolate|4
Sweets|Milk Chocolate|3
Lean Meats|Chicken|2
Lean Meats|Fish|4
Lean Meats|Ground Turkey|2
Lean Meats|Fried Fish|1
;
run;

options dlcreatedir;
libname group 'c:\memlib' memlib;
data group.Grain group.Fruit group.Veg group.Sweet group.Meat missed;
  set have;
  select(food);
    when('Grains')              output group.Grain;
    when('Fruits')              output group.Fruit;
    when('Vegetables/Legumes')  output group.Veg;
    when('Sweets')              output group.Sweet;
    when('Lean Meats')          output group.Meat;
    otherwise output missed;
  end;
run;

data _null_;
  if nobs&amp;gt;0 then
    do;
      put "Missed cases. Fix code";
      abort;
    end;
  stop;
  set missed nobs=nobs;
run;

data want(drop=food group_name points);

  array food_group  {8} $20 Grain Fruit1 Fruit2 Veg1 Veg2 Veg3 Sweet Meat; 
  array point_group {8} _temporary_;

  set group.Grain;
  food_group[1] =Group_Name;
  point_group[1]=points;

  do pFruit=1 to nFruit;
    set group.fruit point=pFruit nobs=nFruit;
    food_group[2] =Group_Name;
    point_group[2]=points;

    do pFruit2=pFruit+1 to nFruit;
      set group.fruit point=pFruit2;
      food_group[3] =Group_Name;
      point_group[3]=points;

      do pVeg=1 to nVeg;
        set group.Veg point=pVeg nobs=nVeg;
        food_group[4] =Group_Name;
        point_group[4]=points;

        do pVeg2=pVeg+1 to nVeg;
          set group.Veg point=pVeg2;
          food_group[5] =Group_Name;
          point_group[5]=points;

          do pVeg3=pVeg2+1 to nVeg;
            set group.Veg point=pVeg3;
            food_group[6] =Group_Name;
            point_group[6]=points;

            do pSweet=1 to nSweet;
              set group.Sweet point=pSweet nobs=nSweet;
              food_group[7] =Group_Name;
              point_group[7]=points;

              do pMeat=1 to nMeat;
                set group.Meat point=pMeat nobs=nMeat;
                food_group[8] =Group_Name;
                point_group[8]=points;
                point_sum=sum(of point_group[*]);
                if point_sum&amp;lt;=25 then output;

              end; /* pMeat */
            end; /* pSweet */
          end; /* pVeg3 */
        end; /* pVeg2 */
      end; /* pVeg */
    end; /* pFruit2 */
  end; /* pFruit */

run;

libname group clear;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Sep 2017 10:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-all-Combinations/m-p/397055#M95931</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-19T10:30:11Z</dc:date>
    </item>
  </channel>
</rss>

