<?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: Create data set with all possible combinations in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956809#M47901</link>
    <description>&lt;P&gt;Are you trying to analyze something or just wanting to create data?&lt;/P&gt;&lt;P&gt;This will assist in determining the best route;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;cartesian join vs cross-tabulation, pivot table?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jan 2025 22:36:20 GMT</pubDate>
    <dc:creator>coder1234</dc:creator>
    <dc:date>2025-01-21T22:36:20Z</dc:date>
    <item>
      <title>Create data set with all possible combinations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956801#M47897</link>
      <description>Hello&lt;BR /&gt;Let's say I want to create a data set with all possible combinations of 9 categorical varaibles . Here are the possible values for each variable:&lt;BR /&gt;X1- 1,2,3&lt;BR /&gt;X2-1,2&lt;BR /&gt;X3-1,2&lt;BR /&gt;X4-1,2,3&lt;BR /&gt;X5-1,2&lt;BR /&gt;X6-1,2,3&lt;BR /&gt;X7-1,2,3,4&lt;BR /&gt;X8-1,2&lt;BR /&gt;X9-1,2,3&lt;BR /&gt;So there are 5184 possible combinations.&lt;BR /&gt;(3×2×2×3×2×3×4×2×3=5184)&lt;BR /&gt;What is the way to create the desired data set with all possible combinations (the data set will have 9 columns :x1-x9)&lt;BR /&gt;May you please show the solution via-&lt;BR /&gt;Way1- Cartesian product&lt;BR /&gt;Way2- Do loop&lt;BR /&gt;Or any other nice way&lt;BR /&gt;Cheers&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Jan 2025 20:41:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956801#M47897</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-01-21T20:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with all possible combinations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956805#M47900</link>
      <description>&lt;P&gt;Or maybe you could try to write something yourself, and then, in case of problems, ask? &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 21:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956805#M47900</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-01-21T21:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with all possible combinations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956809#M47901</link>
      <description>&lt;P&gt;Are you trying to analyze something or just wanting to create data?&lt;/P&gt;&lt;P&gt;This will assist in determining the best route;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;cartesian join vs cross-tabulation, pivot table?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 22:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956809#M47901</guid>
      <dc:creator>coder1234</dc:creator>
      <dc:date>2025-01-21T22:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with all possible combinations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956815#M47906</link>
      <description>&lt;P&gt;If your actual values are sequential integers (not stated, what you show might be character values as "categorical" is a usage not variable type )&lt;/P&gt;
&lt;PRE&gt;data want;
   do x1 = 1 to 3;
   do x2 = 1 to 2;
   do x3 = 1 to 2;
   do x4 = 1 to 3;
   do x5 = 1 to 2;
   do x6 = 1 to 3;
   do x7 = 1 to 4;
   do x8 = 1 to 2;
   do x9 = 1 to 3;
     output;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;If your values are not actually sequential for a given variable then use a list of values for the do: do x= 2,5,27; or what have you. Same for character values.&lt;/P&gt;
&lt;P&gt;Note I didn't bother to indent the code for each level of the DO because that many nested indents can get rendered pretty ugly with tabs set at anything more than 2 or 3 spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code needed to do anything like this with differing numbers of values for each variable would be extremely ugly attempting to use any of the combinatoric functions like ALLCOMB .&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 23:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956815#M47906</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-01-21T23:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with all possible combinations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956822#M47908</link>
      <description>&lt;P&gt;Or more simply:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc plan; 
factors x1=3 ordered x2=2 ordered x3=2 ordered x4=3 ordered x5=2 ordered 
  x6=3 ordered x7=4 ordered x8=2 ordered x9=3 ordered / noprint;
output out=plan;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Remove the ORDERED keywords if you want selections to be random.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 01:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956822#M47908</guid>
      <dc:creator>StatDave</dc:creator>
      <dc:date>2025-01-22T01:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with all possible combinations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956827#M47909</link>
      <description>&lt;P&gt;Your PROC PLAN is just creating a Cartesian Product, just like the following PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select * from
have(keep=x1),
have(keep=x2),
have(keep=x3),
have(keep=x4),
have(keep=x5),
have(keep=x6),
have(keep=x7),
have(keep=x8),
have(keep=x9)
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jan 2025 02:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-data-set-with-all-possible-combinations/m-p/956827#M47909</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-01-22T02:11:14Z</dc:date>
    </item>
  </channel>
</rss>

