<?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: How to create table of every combination of 0s and 1s? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611266#M178126</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array x{*} Apples Oranges Bananas Kiwis;
k=-1;
n=2**dim(x);
do i=1 to n;
 rc=graycode(k,of x{*});
 output;
end;
drop i k n rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 12 Dec 2019 12:54:54 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-12-12T12:54:54Z</dc:date>
    <item>
      <title>How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611114#M178053</link>
      <description>&lt;P&gt;I'm trying to create the table below to hold different flag combinations using zeros and ones.&amp;nbsp; If I already know my column names (Apples, Oranges, Bananas, Kiwis) is there a way to easily generate the table below without manually each individual value?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Apples&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Oranges&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Bananas&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Kiwis&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt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/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611114#M178053</guid>
      <dc:creator>EricSASUser</dc:creator>
      <dc:date>2019-12-11T19:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611118#M178055</link>
      <description>&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2016/02/24/create-a-design-matrix-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2016/02/24/create-a-design-matrix-in-sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 20:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611118#M178055</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-12-11T20:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611122#M178059</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/303259"&gt;@EricSASUser&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of several more elementary ways to create this table is to use nested DO loops:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
retain Apples Oranges Bananas Kiwis; /* variable order */
do Apples =0,1;
  do Oranges=0,1;
    do Kiwis  =0,1;
      do Bananas=0,1;
        output;
      end;
    end;
  end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the RETAIN statement could be omitted if the column order matched the "nesting order."&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's another way, using the binary system:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=i j);
retain Apples Oranges Bananas Kiwis; /* variable order */
array a[*] Apples Oranges Kiwis Bananas;
do i=0 to 2**dim(a)-1;
  do j=1 to dim(a);
    a[j]=~~band(i,2**(dim(a)-j));
  end;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Dec 2019 20:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611122#M178059</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-12-11T20:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611123#M178060</link>
      <description>&lt;P&gt;You can use PROC FACTEX to create a full factorial design.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=qcug&amp;amp;docsetTarget=qcug_factex_gettingstarted02.htm&amp;amp;locale=en"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=qcug&amp;amp;docsetTarget=qcug_factex_gettingstarted02.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which is easier (in my opinion) and less prone to errors than creating the necessary do loops to obtain the desired result. And I don't think the link from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;really addresses how to create a table of all combinations of 0s and 1s.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 20:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611123#M178060</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-11T20:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611266#M178126</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array x{*} Apples Oranges Bananas Kiwis;
k=-1;
n=2**dim(x);
do i=1 to n;
 rc=graycode(k,of x{*});
 output;
end;
drop i k n rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 12:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611266#M178126</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-12T12:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611275#M178133</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;: You were lucky that 4**2 = 2**4. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; But in general the number of combinations should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;n=2**dim(x);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 12:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611275#M178133</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-12-12T12:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611278#M178135</link>
      <description>&lt;P&gt;Opps. There was some thing bad in my mind. Thanks for correct that .&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 12:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611278#M178135</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-12T12:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611288#M178141</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bin;
    input b;
    cards;
0
1
;
run;

proc sql noprint;
    CREATE TABLE fruits AS
    SELECT a.b AS Apples, b.b AS Oranges, c.b AS Bananas, d.b AS Kiwis
    FROM bin a, bin b, bin c, bin d
    ;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 13:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611288#M178141</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-12-12T13:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611293#M178143</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;&amp;nbsp;this is very clever and it works and I wish I had thought of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I am wondering what the reason is that the values in the columns are not in the order I would expect. Since the code has apples first, oranges second, bananas third and kiwis fourth, I would expect apples would show 8 zeros followed by 8 ones (it does), then I expect the second column oranges to show four zeros followed by four ones, repeated twice (it does), then I expect the third column bananas as two zeros followed by two ones, repeated four times (it does not), and then the fourth column kiwis as a zero followed by a 1 repeated 8 times (it does not). Can anyone explain why this unexpected (to me) ordering is happening from this SQL code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 313px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34700iBFF39E2A3B9F8349/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 13:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611293#M178143</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-12T13:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611299#M178149</link>
      <description>&lt;P&gt;#jff &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO cp(dsout=,fruits=,n=);
   %local c currItem;
   %let c=1;
   %let currItem=%scan(&amp;amp;fruits.,&amp;amp;c.,%str( ));
   %DO %WHILE(%length(&amp;amp;currItem.)&amp;gt;0);
      DATA &amp;amp;currItem.;
         %do &amp;amp;currItem.=0 %to &amp;amp;n.;
            &amp;amp;currItem.=&amp;amp;&amp;amp;&amp;amp;currItem.;output;
         %end;
      RUN;
      %let c=%eval(&amp;amp;c.+1);
      %let currItem=%scan(&amp;amp;fruits.,&amp;amp;c.,%str( ));
   %END;

   DATA _NULL_;
      call execute("PROC SQL;CREATE TABLE cartesian AS SELECT * FROM %sysfunc(translate(&amp;amp;fruits.,',',' '));");
      call execute("drop table %sysfunc(translate(&amp;amp;fruits.,',',' '));QUIT;");
   RUN;
   PROC PRINT;RUN;
%MEND cp;
%cp(dsout=cartesian,fruits=apples oranges bananas kiwis,n=1); &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 13:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611299#M178149</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2019-12-12T13:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611306#M178155</link>
      <description>&lt;P&gt;Hi, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; and thanks for your kind comments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know why the columns are ordered that (unintuitive) way.&lt;/P&gt;
&lt;P&gt;It seems that the possible values are first looped on the third column, then the fourth, fifth and so on...&lt;/P&gt;
&lt;P&gt;second and first columns are the last ones where the loop on values occurs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an (incomplete) example with more values and columns&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2019-12-12 15_00_02-SAS - [VIEWTABLE_ Work.Test].png" style="width: 304px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34701iB978FFF2B53F6720/image-size/large?v=v2&amp;amp;px=999" role="button" title="2019-12-12 15_00_02-SAS - [VIEWTABLE_ Work.Test].png" alt="2019-12-12 15_00_02-SAS - [VIEWTABLE_ Work.Test].png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess it may just be a consequence of the particular algorithm used to perform cartesian&lt;/P&gt;
&lt;P&gt;product.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 14:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611306#M178155</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-12-12T14:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611331#M178170</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cartesian(drop=i j);
   array fruits apples bananas oranges kiwis;
   do i=1 to 2**dim(fruits);
      do j=1 to dim(fruits);
         fruits(j)=input(substr(put(i,binary.),j,1),best.);
      end;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 14:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611331#M178170</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2019-12-12T14:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611380#M178174</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;: Good question. I also don't know the algorithm used by PROC SQL behind the scenes which determines the sort order. I would add an ORDER BY clause to be on the safe side (independent of platform, OS, SAS version, ... influences):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;order by 1,2,4,3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The _METHOD option of the PROC SQL statement reveals that there is some sort of tree-type hierarchy (keeping pairs of adjacent variables together) in the way the query is structured internally. So it's definitely not just "linear." Here's the log for seven (instead of four) variables:&lt;/P&gt;
&lt;PRE&gt;NOTE: SQL execution methods chosen are:

      sqxcrta
          sqxjsl
              sqxjsl
                  sqxsrc( WORK.BIN(alias = G) )
                  sqxjsl
                      sqxsrc( WORK.BIN(alias = D) )
                      sqxsrc( WORK.BIN(alias = C) )
              sqxjsl
                  sqxjsl
                      sqxsrc( WORK.BIN(alias = A) )
                      sqxsrc( WORK.BIN(alias = B) )
                  sqxjsl
                      sqxsrc( WORK.BIN(alias = E) )
                      sqxsrc( WORK.BIN(alias = F) )&lt;/PRE&gt;
&lt;P&gt;On my computer the sort orders for 2, 3, ..., 8 variables are:&lt;/P&gt;
&lt;PRE&gt;# vars  order
   2    1,2
   3    3,1,2
   4    1,2,4,3
   5    1,2,5,4,3
   6    5,6,1,2,4,3
   7    7,4,3,1,2,5,6
   8    1,2,4,3,7,8,5,6&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Luckily, other procedures that could be used produce predictable results, e.g., PROC SUMMARY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fruits;
output;
Apples+1; Oranges+1; Kiwis+1; Bananas+1;
output;
run;

proc summary data=fruits nway completetypes;
class _all_;
output out=want(drop=_:); /* different variable order, though */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or PROC FREQ:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=fruits noprint;
tables Apples*Oranges*Kiwis*Bananas / sparse out=want(label=' ' drop=count percent);
run;                                 /* different variable order, though */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 16:57:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611380#M178174</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-12-12T16:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611704#M178333</link>
      <description>&lt;P&gt;Thanks everyone.&amp;nbsp; This is great.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 19:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611704#M178333</guid>
      <dc:creator>EricSASUser</dc:creator>
      <dc:date>2019-12-13T19:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to create table of every combination of 0s and 1s?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611715#M178340</link>
      <description>This might be easiest way.</description>
      <pubDate>Fri, 13 Dec 2019 19:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-table-of-every-combination-of-0s-and-1s/m-p/611715#M178340</guid>
      <dc:creator>EricSASUser</dc:creator>
      <dc:date>2019-12-13T19:49:59Z</dc:date>
    </item>
  </channel>
</rss>

