<?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 dummy code matrices from all combinations of a set of stratifying variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397629#M278297</link>
    <description>&lt;P&gt;thanks for the quick reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it's in order to perform an indirect adjustment in a Cox model using two distinct but representative datasets. The model has 4 stratifying variables (sex, 5-year age groups, urban size and airshed).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't think those suggestions will work easily as I need the program to loop through all possible combinations of the stratifying variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Sep 2017 22:03:27 GMT</pubDate>
    <dc:creator>acerickson</dc:creator>
    <dc:date>2017-09-20T22:03:27Z</dc:date>
    <item>
      <title>create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397623#M278295</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I'm a SAS noob (using SAS 9.4) and couldn't find an existing question to satisfy my question, so here I am.&lt;BR /&gt;&lt;BR /&gt;I need to create a series of dummy variable matrices of&amp;nbsp;several categorical variables for all possible combinations of a set of stratifying variables. In the simplified example below, I input the 4 actual stratifying variables and possible values (a-d), and 2 categorical variables (ms3c and edu2c). If you run the code below, the resulting datasets (test2, test3) represent what I will want as output but as separate csv files. SHould end up with 840 different matrices.&lt;BR /&gt;&lt;BR /&gt;I have been try to include a 'allcomb' function in a DO Loop, but can't figure out the syntax.&lt;BR /&gt;Thanks for any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1; 
input uid a b c d ms3c edu2c;
cards;
1 1 1 1 1 2 2
2 1 2 1 1 3 2
3 1 3 3 3 3 1
4 2 4 4 4 2 1
5 1 5 5 5 1 2
6 2 6 1 6 2 1
7 1 7 2 7 1 2
8 2 8 3 6 3 2
9 1 9 4 5 3 1
10 2 10 5 4 2 2
11 2 11 1 3 2 2
12 1 12 2 2 1 2
13 1 1 1 1 3 1
14 1 2 1 1 2 2
15 2 3 5 3 2 1
run;

* this gives an idea of what I need to do, create 1 matrix for every combination of strata variables; 
data test2 (drop=uid a b c d ms3c edu2c);
 set test1;
 if a=1 and b=1 and c=1 and d=1 and ms3c=2 then ms2=1; else ms2=0;
 if a=1 and b=1 and c=1 and d=1 and ms3c=3 then ms3=1; else ms3=0;
 if a=1 and b=1 and c=1 and d=1 and edu2c=2 then edu2=1; else edu2=0;
 * export to csv;
run;
*;
data test3 (drop=uid a b c d ms3c edu2c);
 set test1;
 if a=1 and b=2 and c=1 and d=1 and ms3c=2 then ms2=1; else ms2=0;
 if a=1 and b=2 and c=1 and d=1 and ms3c=3 then ms3=1; else ms3=0;
 if a=1 and b=2 and c=1 and d=1 and edu2c=2 then edu2=1; else edu2=0;
* export to csv;
run;
* ... and so on ...;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Sep 2017 21:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397623#M278295</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-20T21:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397625#M278296</link>
      <description>&lt;P&gt;First question, why are you doing this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second:&lt;/P&gt;
&lt;P&gt;I've listed a few of the options here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-dummy-variables-Categorical-Variables/ta-p/308484" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-dummy-variables-Categorical-Variables/ta-p/308484&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do any of those work for you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/166477"&gt;@acerickson&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;BR /&gt;I'm a SAS noob (using SAS 9.4) and couldn't find an existing question to satisfy my question, so here I am.&lt;BR /&gt;&lt;BR /&gt;I need to create a series of dummy variable matrices of&amp;nbsp;several categorical variables for all possible combinations of a set of stratifying variables. In the simplified example below, I input the 4 actual stratifying variables and possible values (a-d), and 2 categorical variables (ms3c and edu2c). If you run the code below, the resulting datasets (test2, test3) represent what I will want as output but as separate csv files. SHould end up with 840 different matrices.&lt;BR /&gt;&lt;BR /&gt;I have been try to include a 'allcomb' function in a DO Loop, but can't figure out the syntax.&lt;BR /&gt;Thanks for any help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1; 
input uid a b c d ms3c edu2c;
cards;
1 1 1 1 1 2 2
2 1 2 1 1 3 2
3 1 3 3 3 3 1
4 2 4 4 4 2 1
5 1 5 5 5 1 2
6 2 6 1 6 2 1
7 1 7 2 7 1 2
8 2 8 3 6 3 2
9 1 9 4 5 3 1
10 2 10 5 4 2 2
11 2 11 1 3 2 2
12 1 12 2 2 1 2
13 1 1 1 1 3 1
14 1 2 1 1 2 2
15 2 3 5 3 2 1
run;

* this gives an idea of what I need to do, create 1 matrix for every combination of strata variables; 
data test2 (drop=uid a b c d ms3c edu2c);
 set test1;
 if a=1 and b=1 and c=1 and d=1 and ms3c=2 then ms2=1; else ms2=0;
 if a=1 and b=1 and c=1 and d=1 and ms3c=3 then ms3=1; else ms3=0;
 if a=1 and b=1 and c=1 and d=1 and edu2c=2 then edu2=1; else edu2=0;
 * export to csv;
run;
*;
data test3 (drop=uid a b c d ms3c edu2c);
 set test1;
 if a=1 and b=2 and c=1 and d=1 and ms3c=2 then ms2=1; else ms2=0;
 if a=1 and b=2 and c=1 and d=1 and ms3c=3 then ms3=1; else ms3=0;
 if a=1 and b=2 and c=1 and d=1 and edu2c=2 then edu2=1; else edu2=0;
* export to csv;
run;
* ... and so on ...;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 21:45:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397625#M278296</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-20T21:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397629#M278297</link>
      <description>&lt;P&gt;thanks for the quick reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it's in order to perform an indirect adjustment in a Cox model using two distinct but representative datasets. The model has 4 stratifying variables (sex, 5-year age groups, urban size and airshed).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't think those suggestions will work easily as I need the program to loop through all possible combinations of the stratifying variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 22:03:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397629#M278297</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-20T22:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397631#M278298</link>
      <description>&lt;P&gt;1) I don't think that your "and so on" after data test3 is as obvious as you think it may be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am a tad concerned about resue of the dummy variable names ms2, ms3 and edu2. Same variable name with different meanings will almost always lead to some confusion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I find the easiest, though not the most elegant, way to get "all combinations" of multiple variables is nested arrays. I can't actually tell whay your limits are on each variable but this should demonstrate:&lt;/P&gt;
&lt;PRE&gt;data example;
   /* variable a to have ranges of 1,2,3
      variable b to have range of 88,99
      variable c to have range of 'AB', 'AC', 'EX'
   */
   do a= 1 to 3;
      do b = 88,99;
         do c = 'AB','AC','EX';
         output;
         end;
      end;
   end;
run;
&lt;/PRE&gt;
&lt;P&gt;The example provides a mix of sequential integers, non-sequential integers and a character variable. The order of the nesting isn't really import though that output statement is critical.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How you use those to make your dummies is up to you. I would likely be tempted to put the code for that in the innermost do loop (BEFORE the output), but that would require different names from the way you did it.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 22:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397631#M278298</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-20T22:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397632#M278299</link>
      <description>&lt;P&gt;Can we&amp;nbsp;assume you're familiar with how SAS handles CLASS and STRATA variables then?&lt;/P&gt;
&lt;P&gt;And that SAS automatically creates the dummy variables for all levels present in the data already?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 22:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397632#M278299</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-20T22:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397636#M278300</link>
      <description>&lt;P&gt;thanks for the response, that a helpful start. &amp;nbsp;I can use different variable names, that's no problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;apologies for the unclear description.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are 4 stratifying variables with the following ranges:&lt;/P&gt;&lt;P&gt;a (1,2)&lt;/P&gt;&lt;P&gt;b (1,12)&lt;/P&gt;&lt;P&gt;c (1,5)&lt;/P&gt;&lt;P&gt;d (1,7)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so what I mean by the "..and so on..." comment, is that I would need to repeat those 3 IF statements 840 times in order to cycle through all possible combinations of the 4 stratifying variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 22:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397636#M278300</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-20T22:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397647#M278301</link>
      <description>&lt;P&gt;yes, that is within the PROC statement for the Cox model (e.g. proc phreg).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm calculating a series of Cox models, then taking a summed&amp;nbsp;ratio of them (see attached for a summary slide).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 23:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397647#M278301</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-20T23:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397655#M278302</link>
      <description>&lt;P&gt;Really just a shot in the dark here, since it's too difficult for me to figure out what you will do with this later. &amp;nbsp;Can't you just use a single variable that takes on 840 different values? &amp;nbsp;The matrix would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data all_combinations;&lt;/P&gt;
&lt;P&gt;do a=1 to 2;&lt;/P&gt;
&lt;P&gt;do b=1 to 12;&lt;/P&gt;
&lt;P&gt;do c=1 to 5;&lt;/P&gt;
&lt;P&gt;do d=1 to 7;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;single_variable = d + 10*c + 100*b + 10000 * a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end; end; end; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need 10,000 (not 1,000) as the multiplier for A, since B can be two digits.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 00:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397655#M278302</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-21T00:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397676#M278303</link>
      <description>&lt;P&gt;Couldn't you just put them into the BY statement or does that mess up something else?&lt;/P&gt;
&lt;P&gt;Note that STRATA is different than BY so if you're including them in the STRATA this isn't possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as you have data for each stratum SAS will process it appropriately.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/166477"&gt;@acerickson&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;thanks for the response, that a helpful start. &amp;nbsp;I can use different variable names, that's no problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;apologies for the unclear description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are 4 stratifying variables with the following ranges:&lt;/P&gt;
&lt;P&gt;a (1,2)&lt;/P&gt;
&lt;P&gt;b (1,12)&lt;/P&gt;
&lt;P&gt;c (1,5)&lt;/P&gt;
&lt;P&gt;d (1,7)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so what I mean by the "..and so on..." comment, is that I would need to repeat those 3 IF statements 840 times in order to cycle through all possible combinations of the 4 stratifying variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks again!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 02:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397676#M278303</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-21T02:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397850#M278304</link>
      <description>&lt;P&gt;thanks for the input, I'm trying to think how to possibly make this work... &amp;nbsp;if I was able to assign the new 'single_variable' to the corresponding individual records based on their values for the variables a to d, that would be something.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 17:54:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397850#M278304</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-21T17:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397855#M278305</link>
      <description>&lt;P&gt;thanks again for your time and effort on this, I'm not really making it easier for you folks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thinking about it more, I think Astounding might be onto something - I should be able to do a one-to-many merge of the unique 'single_variable' back into my main dataset matching on the 4 strata variables, correct? This could solve a couple issues, like ensuring at least one event (death) occurs in each strata, and if there are any unpopulated strata.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 18:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397855#M278305</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-21T18:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397856#M278306</link>
      <description>&lt;P&gt;&lt;SPAN&gt;thinking about it more, I think you&amp;nbsp;might be onto something - I should be able to do a one-to-many merge of the unique 'single_variable' back into my main dataset matching on the 4 strata variables, correct?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 18:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397856#M278306</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-21T18:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397859#M278307</link>
      <description>&lt;P&gt;Couldn't you just use the same formula for SINGLE_VARIABLE, using A, B, C, and D that are found in your data?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 18:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397859#M278307</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-21T18:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397944#M278308</link>
      <description>&lt;P&gt;yes, exactly. This is great as it solves a couple other questions, but still need to create the matrices.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So now I have this 'all_combinations' variable that identifies which of the 840 strata an individual belongs to, so now I can run a BY statement to create the matrices.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 21:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397944#M278308</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-21T21:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397964#M278309</link>
      <description>&lt;P&gt;so close to solving this, just need help with the syntax using a FILE statement with the filevar= option.&lt;/P&gt;&lt;P&gt;Was trying to follow the steps from the FILE statement page&amp;nbsp;&lt;A href="https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000171874.htm" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* create a new variable identifying the unique strata;
data all_combinations;
do a=1 to 2;
do b=1 to 12;
do c=1 to 5;
do d=1 to 7;
   single_variable = d + 10*c + 100*b + 10000 * a;
   output;
end; end; end; end;
run;

* now merge that back to the main dataset;
proc sort data=test1;
  by a b c d;
run;
proc sort data=all_combinations;
  by a b c d;
run;
data merge1;
  merge test1 all_combinations;
  by a b c d;
run;

/* now create the separate matrices based on the distinct 840 strata 
using a FILE statement to export to a CSV and dynamically update the 
filename to reflect its strata */
* may need to convert 'single_variable' to a character (from numeric);

data test4 (keep= ms2 ms3 edu2);
  set merge1;
  if ms3c=2 then ms2=1; else ms2=0;
  if ms3c=3 then ms3=1; else ms3=0;
  if edu2c=2 then edu2=1; else edu2=0;
  by single_variable;
  file file-specification &amp;lt;device-type&amp;gt; filevar=sinlge_variable; * need help here;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Sep 2017 23:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/397964#M278309</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-21T23:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/398031#M278310</link>
      <description>&lt;P&gt;A few notes then ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When using FILEVAR=, the file-specification is just a place holder. &amp;nbsp;You can use any name not already defined by your program, such as _out_. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The device-type is optional and rarely used. &amp;nbsp;Just remove it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The general idea is to create a character variable holding the complete path to the output file you would like to use. &amp;nbsp;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;destination = 'C:\myfolder\combination' || put(single_variable, z5.) || '.txt';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then complete the FILE statement with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;filevar = destination;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 10:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/398031#M278310</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-22T10:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/398245#M278311</link>
      <description>&lt;P&gt;still having issues with creating the separate files (couldn't get the FILE statement to work properly)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* want to create a series of tables that loop through&lt;BR /&gt;the values of a variable (single_variable) and name it&lt;BR /&gt;with the corresponding value with the prefix "xmat_". */

**** for example *** ;
proc sql ; 
    create table xmat_10111 as select *
    FROM test4
   where single_variable=10111;
* repeat where single_variable =10111 to 21257;
*******************************************;

* what I have so far is;

%macro trial;
%do i=10111 %to 21257;
proc sql ; 
	create table xmat_%i as select *
	FROM test4
	where single_variable=%i;
%end;

%mend ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2017 00:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/398245#M278311</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-23T00:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/398246#M278312</link>
      <description>&lt;P&gt;Be glad you didn't get this to work. &amp;nbsp;Remember SINGLE_VARIABLE only takes on 840 values. If this had worked, you would have created about 10,000 empty tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing to fix (before we abandon this approach) is that you refer to a macro variable with an ampersand: &amp;nbsp;&amp;amp;i rather than %i&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A better way to generate 840 CREATE statements, assuming you have that data set ALL_COMBINATIONS:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;call execute('proc sql'; ) ;&lt;/P&gt;
&lt;P&gt;do until (done);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set all_combinations end=done;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;dsname = put(single_variable, z5.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;call execute('create table xmat_' || dsname || ' as select * from test4 where single_variable= ' || dsname || ';' ) ;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;call execute('quit;' ) ;&lt;/P&gt;
&lt;P&gt;stop;&lt;/P&gt;
&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2017 00:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/398246#M278312</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-23T00:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/398248#M278313</link>
      <description>&lt;P&gt;I feel like we're missing something giant here. Are you then exporting the data out to do the regressions in some other tool? Otherwise, why split the files in the first place or create the single indicator, SAS will handle all of that directly into a BY.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same thing with the export, you don't need to precalculate it, just sort your data by A/B/C/D and then create the files dynamically using the data step as illustrated.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2017 00:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/398248#M278313</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-23T00:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: create dummy code matrices from all combinations of a set of stratifying variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/398650#M278314</link>
      <description>&lt;P&gt;Brilliant! Thank you*840 &amp;nbsp;to Astounding.&lt;/P&gt;&lt;P&gt;So putting it all together we have the following. Perhaps there is a more efficient program, but I am happy with this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* create a new variable identifying the unique strata;
data all_combinations;
    do a=1 to 2;
    do b=1 to 12;
    do c=1 to 5;
    do d=1 to 7;
        single_variable = d + 10*c + 100*b + 10000 * a;
   output;
end; end; end; end;
run;

* now merge that back to the main dataset (test1);
proc sort data=test1;
    by a b c d;
run;
proc sort data=all_combinations;
    by a b c d;
run;
data merge1;
    merge test1 all_combinations;
    by a b c d;
run;

* create the dummy codes by strata for the variables (ms3c and edu2c);
data test2 (keep= single_variable ms2 ms3 edu2);
  set merge1;
    if ms3c=2 then ms2=1; else ms2=0;
    if ms3c=3 then ms3=1; else ms3=0;
    if edu2c=2 then edu2=1; else edu2=0;
run;

* now create a dummy code matrix table for each unique strata (840) and name the tables with the strata id code (single_variable);
data _null_;
call execute('proc sql') ;
do until (done);
   set test2 end=done;
   dsname = put(single_variable, z5.);
   call execute('create table xmat_' || dsname || ' as select * from test4 where single_variable= ' || dsname || ';' ) ;
end;
call execute('quit;' ) ;
stop;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 20:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dummy-code-matrices-from-all-combinations-of-a-set-of/m-p/398650#M278314</guid>
      <dc:creator>acerickson</dc:creator>
      <dc:date>2017-09-25T20:03:53Z</dc:date>
    </item>
  </channel>
</rss>

