<?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 Juletip #15 - Listing all possible combinations of Santa's deers in SAS Community Nordic</title>
    <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-15-Listing-all-possible-combinations-of-Santa-s-deers/m-p/849796#M401</link>
    <description>&lt;P&gt;/*****************************************************************************************&lt;/P&gt;
&lt;P&gt;This code creates all possible combinations for a set of items.&lt;/P&gt;
&lt;P&gt;Here we want to list all possible combinations of Santa's 8 reindeers to help Rudolf to &lt;BR /&gt;pull the sledge. Rudolf is always needed to share light with his nose.&lt;/P&gt;
&lt;P&gt;Code utilises the binary representation of numbers, and the fact that between 9 digit &lt;BR /&gt;binary number 00000000 (i.e. 0) and 11111111 (i.e. 255) all possible combinations of 1's &lt;BR /&gt;and 0's are represented.&lt;/P&gt;
&lt;P&gt;If the n'th digit of the binary string is 1, we concatenate the name of the n'th deer &lt;BR /&gt;into the resulting text. Here the resulting variable is named: Combination.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;******************************************************************************************/ &lt;BR /&gt;%let N = 8; &lt;BR /&gt;%let _DEERS = 'Dasher', 'Dancer', 'Prancer', 'Vixen', 'Comet', 'Cupid', 'Donner', 'Blitzen';&lt;/P&gt;
&lt;P&gt;data _null_; &lt;BR /&gt;&amp;nbsp; &amp;nbsp;length Combinations $ 240; &lt;BR /&gt;&amp;nbsp; &amp;nbsp;array Reindeers{&amp;amp;n.} $ (&amp;amp;_DEERS.);&lt;/P&gt;
&lt;P&gt;/* "_n_of_ones_" is an auxiliary variable containing the number of 1's in the 9 digit binary string. */ &lt;BR /&gt;&amp;nbsp; &amp;nbsp;_n_of_ones_ = count(put( 0, binary&amp;amp;n..), "1");&lt;/P&gt;
&lt;P&gt;/* We iterate the code until the whole binary string is full of 1's. */ &lt;BR /&gt;&amp;nbsp; &amp;nbsp;do until(_n_of_ones_ eq dim(Reindeers)); &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; _iteration_ + 1; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Combinations = "Rudolph";&lt;/P&gt;
&lt;P&gt;/* Variable "i" loops through the 0's and 1's in the current binary string. */ &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;do i = 1 to dim(Reindeers);&lt;/P&gt;
&lt;P&gt;/* If current char in the binary string is "1", we concatenate the text into the resulting variable. */ &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if substr(put(_iteration_, binary&amp;amp;n..), i, 1) = "1" &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;then Combinations = catx(" + ", Combinations, Reindeers{i}); &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; put Combinations =;&lt;/P&gt;
&lt;P&gt;/* We check how many 1's there is in the binary string in this iteration. */ &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; _n_of_ones_ = count(put(_iteration_, binary&amp;amp;n..), "1"); &lt;BR /&gt;&amp;nbsp; &amp;nbsp; end; &lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Dec 2022 07:42:35 GMT</pubDate>
    <dc:creator>JussiV</dc:creator>
    <dc:date>2022-12-15T07:42:35Z</dc:date>
    <item>
      <title>Juletip #15 - Listing all possible combinations of Santa's deers</title>
      <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-15-Listing-all-possible-combinations-of-Santa-s-deers/m-p/849796#M401</link>
      <description>&lt;P&gt;/*****************************************************************************************&lt;/P&gt;
&lt;P&gt;This code creates all possible combinations for a set of items.&lt;/P&gt;
&lt;P&gt;Here we want to list all possible combinations of Santa's 8 reindeers to help Rudolf to &lt;BR /&gt;pull the sledge. Rudolf is always needed to share light with his nose.&lt;/P&gt;
&lt;P&gt;Code utilises the binary representation of numbers, and the fact that between 9 digit &lt;BR /&gt;binary number 00000000 (i.e. 0) and 11111111 (i.e. 255) all possible combinations of 1's &lt;BR /&gt;and 0's are represented.&lt;/P&gt;
&lt;P&gt;If the n'th digit of the binary string is 1, we concatenate the name of the n'th deer &lt;BR /&gt;into the resulting text. Here the resulting variable is named: Combination.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;******************************************************************************************/ &lt;BR /&gt;%let N = 8; &lt;BR /&gt;%let _DEERS = 'Dasher', 'Dancer', 'Prancer', 'Vixen', 'Comet', 'Cupid', 'Donner', 'Blitzen';&lt;/P&gt;
&lt;P&gt;data _null_; &lt;BR /&gt;&amp;nbsp; &amp;nbsp;length Combinations $ 240; &lt;BR /&gt;&amp;nbsp; &amp;nbsp;array Reindeers{&amp;amp;n.} $ (&amp;amp;_DEERS.);&lt;/P&gt;
&lt;P&gt;/* "_n_of_ones_" is an auxiliary variable containing the number of 1's in the 9 digit binary string. */ &lt;BR /&gt;&amp;nbsp; &amp;nbsp;_n_of_ones_ = count(put( 0, binary&amp;amp;n..), "1");&lt;/P&gt;
&lt;P&gt;/* We iterate the code until the whole binary string is full of 1's. */ &lt;BR /&gt;&amp;nbsp; &amp;nbsp;do until(_n_of_ones_ eq dim(Reindeers)); &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; _iteration_ + 1; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Combinations = "Rudolph";&lt;/P&gt;
&lt;P&gt;/* Variable "i" loops through the 0's and 1's in the current binary string. */ &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;do i = 1 to dim(Reindeers);&lt;/P&gt;
&lt;P&gt;/* If current char in the binary string is "1", we concatenate the text into the resulting variable. */ &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if substr(put(_iteration_, binary&amp;amp;n..), i, 1) = "1" &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;then Combinations = catx(" + ", Combinations, Reindeers{i}); &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; put Combinations =;&lt;/P&gt;
&lt;P&gt;/* We check how many 1's there is in the binary string in this iteration. */ &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; _n_of_ones_ = count(put(_iteration_, binary&amp;amp;n..), "1"); &lt;BR /&gt;&amp;nbsp; &amp;nbsp; end; &lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 07:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-15-Listing-all-possible-combinations-of-Santa-s-deers/m-p/849796#M401</guid>
      <dc:creator>JussiV</dc:creator>
      <dc:date>2022-12-15T07:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Juletip #15 - Listing all possible combinations of Santa's deers</title>
      <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-15-Listing-all-possible-combinations-of-Santa-s-deers/m-p/850105#M403</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nice and fun thinking (it works!) , but instead of racking my brain , I would let SAS do all the work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See here :&lt;/P&gt;
&lt;P&gt;Generate combinations in SAS &lt;BR /&gt;By Rick Wicklin on The DO Loop September 30, 2013&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2013/09/30/generate-combinations-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2013/09/30/generate-combinations-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also possible with PROC PLAN (SAS/STAT) and for sure also with SAS/OR (PROC CPM?).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 16:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-15-Listing-all-possible-combinations-of-Santa-s-deers/m-p/850105#M403</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-12-16T16:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Juletip #15 - Listing all possible combinations of Santa's deers</title>
      <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-15-Listing-all-possible-combinations-of-Santa-s-deers/m-p/850146#M404</link>
      <description>&lt;P&gt;An alternate approach using the ALLCOMB function:&lt;/P&gt;
&lt;P&gt;The Select is to pick which values to display from the array. The If j le ncomb is because the loop for J increments one additional time to, in effect reset the array and can result in duplicate output when displayed for the "ncomb+1" output.&lt;/P&gt;
&lt;PRE&gt;data _null_;
   array x[8] $ 10 ( 'Dasher', 'Dancer', 'Prancer', 'Vixen', 'Comet', 'Cupid', 'Donner', 'Blitzen');
   n=dim(x);
   do k=1 to dim(x);
      ncomb=comb(n, k);
      do j=1 to ncomb+1;
         rc=allcomb(j, k, of x[*]);
         if j le ncomb then  select (k);
            when (1) put  x1;
            when (2) put  x1-x2;
            when (3) put  x1-x3;
            when (4) put  x1-x4;
            when (5) put  x1-x5;
            when (6) put  x1-x6;
            when (7) put  x1-x7;
            when (8) put  x1-x8;
         end;
      end;
   end;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For added interest use the ALLPERM to generate all the permutations of order the reindeer could be harnessed to the sleigh.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 20:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-15-Listing-all-possible-combinations-of-Santa-s-deers/m-p/850146#M404</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-12-16T20:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Juletip #15 - Listing all possible combinations of Santa's deers</title>
      <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-15-Listing-all-possible-combinations-of-Santa-s-deers/m-p/850387#M407</link>
      <description>&lt;P&gt;For more about how all the combinations that Santa can use to pull his sleigh, see&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2022/12/19/combinations-in-sas.html" target="_self"&gt;"Working with combinations in SAS"&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2022 21:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-15-Listing-all-possible-combinations-of-Santa-s-deers/m-p/850387#M407</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-12-19T21:02:00Z</dc:date>
    </item>
  </channel>
</rss>

