<?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: SAS Macro &amp;amp; Nested Do Loop to subset data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895068#M353581</link>
    <description>&lt;P&gt;Thank you so much once again for your quickly reply, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; . Here is my challenge: the subsets will be overlapping. For example, sampleid 111 will be a combination of 112 and 113. I could not figure out how to create sample IDs without overwriting the existing ones.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Sep 2023 14:36:37 GMT</pubDate>
    <dc:creator>finans_sas</dc:creator>
    <dc:date>2023-09-20T14:36:37Z</dc:date>
    <item>
      <title>SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895061#M353575</link>
      <description>&lt;P&gt;Hello Everyone:&lt;/P&gt;
&lt;P&gt;I have a big dataset, and I want to create subsets from this dataset and combine all the subsets into a separate dataset. Here are more details:&lt;/P&gt;
&lt;P&gt;corvar1 through corvar12: 12 different dummy variables. Each variable takes the value of 0 or 1.&lt;/P&gt;
&lt;P&gt;allmdummy: a dummy variable that takes the value of 0 or 1.&lt;/P&gt;
&lt;P&gt;I want to create 108 different subsets. For example, for corvar1, I would like to create the following nine subsets:&lt;/P&gt;
&lt;P&gt;corvar1 &lt;FONT color="#000080"&gt;le&lt;/FONT&gt; 1 + allmdummy le 1&amp;nbsp;&amp;nbsp; (include all values of corvar1 and all values of allmdummy)&lt;/P&gt;
&lt;P&gt;corvar1 &lt;FONT color="#000080"&gt;le&lt;/FONT&gt; 1 + allmdummy eq 1&lt;/P&gt;
&lt;P&gt;corvar1 &lt;FONT color="#000080"&gt;le&lt;/FONT&gt; 1 + allmdummy lt 1&lt;/P&gt;
&lt;P&gt;corvar1 &lt;FONT color="#800000"&gt;eq&lt;/FONT&gt; 1 + allmdummy le 1&lt;/P&gt;
&lt;P&gt;corvar1 &lt;FONT color="#800000"&gt;eq&lt;/FONT&gt; 1 + allmdummy eq 1&lt;/P&gt;
&lt;P&gt;corvar1 &lt;FONT color="#800000"&gt;eq&lt;/FONT&gt; 1 + allmdummy lt 1&lt;/P&gt;
&lt;P&gt;corvar1 &lt;FONT color="#FF00FF"&gt;lt&lt;/FONT&gt; 1 + allmdummy le 1&lt;/P&gt;
&lt;P&gt;corvar1 &lt;FONT color="#FF00FF"&gt;lt&lt;/FONT&gt; 1 + allmdummy eq 1&lt;/P&gt;
&lt;P&gt;corvar1 &lt;FONT color="#FF00FF"&gt;lt&lt;/FONT&gt; 1 + allmdummy lt 1 (include only the values where corvar1=0 and allmdummy=0).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is a rough sketch of what I would like to accomplish. I would love to have your help with improving this code.&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;%macro groupa;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;%do cvar=1 %to 12; /*names for the variables*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;%do m=1 %to 3; /*for math operations*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;%do n=1 %to 3; /*for math operations*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;data set&amp;amp;cvar&amp;amp;m&amp;amp;n; set regsample;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;if &amp;amp;m=1 then opa="le";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;if &amp;amp;m=2 then opa="eq";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;if &amp;amp;m=3 then opa="lt";&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;if &amp;amp;n=1 then opb="le";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;if &amp;amp;n=2 then opb="eq";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;if &amp;amp;n=3 then opb="lt";&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;if corvar&amp;amp;cvar opa 1 and allmdummy opb 1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;id1=&amp;amp;cvar;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;id2=&amp;amp;m;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;id3=&amp;amp;n;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;sampleid=&amp;amp;cvar&amp;amp;m&amp;amp;n; /*create a sample ID*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;proc append base=wanted data=set&amp;amp;cvar&amp;amp;m&amp;amp;n; /*I want to combine all the datasets into a single one. Not sure if this syntax is right*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;%end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;%end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;%end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;%mend groupa;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;%groupa&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895061#M353575</guid>
      <dc:creator>finans_sas</dc:creator>
      <dc:date>2023-09-20T14:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895062#M353576</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1906"&gt;@finans_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a big dataset, and I want to create subsets from this dataset and combine all the subsets into a separate dataset.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why do this? Why not leave the data set as one big data set, then no splitting and re-combining is needed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, splitting large data sets into smaller data sets is a sub-optimal approach in most situations.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:09:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895062#M353576</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-20T14:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895064#M353577</link>
      <description>&lt;P&gt;Thank you so much, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; for your prompt reply. You made an excellent point. It is a nice segway into my end goal. I actually want to run the following for each sampleid (assuming that wanted is the output of the prior macro). If I could find a way to incorporate the prior macro into the next one, that will indeed save me a lot of time. I will really appreciate any insight on this one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;proc reg data=wanted noprint outest=wanted2 noprint adjrsq;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;by sample id obsid;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*obsid is another ID already stored in the dataset*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;model depvar1 = ind1 ind2 ind3 ind4 / hcc;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;proc means data=wanted2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;by sampleid;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;var intercept ind1 ind2 ind3 ind4 _rsq_ _adjrsq_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;output out=wanted3 mean = std= t= probt= / autoname;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895064#M353577</guid>
      <dc:creator>finans_sas</dc:creator>
      <dc:date>2023-09-20T14:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895065#M353578</link>
      <description>&lt;P&gt;It's still not clear to me why you would not simply take the big data set, assign appropriate values to variable SampleID (without splitting up the big data set), and then use this big data set which now has values for SampleID in PROC MEANS and PROC REG.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895065#M353578</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-20T14:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895067#M353580</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;often asks (wisely), what comes next after you have replicated your data in this way?&amp;nbsp; It looks like you are creating subsets (non-exclusive) and then stacking them back together.&amp;nbsp; There are situations where this is useful (e.g. for simulations), but this may not be one of those situations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to analyze data for different subsets, you can leave the data as is, and then use a WHERE statement to identify subsets of interest.&amp;nbsp; e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc whatever; 
  where corvar1 le 1 and  allmdummy le 1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want 108 different subsets, you could generate it with code like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data big;
  set have;
  if corvar1 le 1 and allmdummy le 1 then do;
    subset=1;
    output; 
  end;
  
  if corvar1 le 1 and allmdummy eq 1 then do;
    subset=2;
    output; 
  end;

  *...;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you might use a macro or some other code generation technique to create the list of IF statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your current IF statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if corvar&amp;amp;cvar opa 1 and allmdummy opb 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can't work because the data step compiler won't see the operators when the step tries to compile.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895067#M353580</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-09-20T14:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895068#M353581</link>
      <description>&lt;P&gt;Thank you so much once again for your quickly reply, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; . Here is my challenge: the subsets will be overlapping. For example, sampleid 111 will be a combination of 112 and 113. I could not figure out how to create sample IDs without overwriting the existing ones.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895068#M353581</guid>
      <dc:creator>finans_sas</dc:creator>
      <dc:date>2023-09-20T14:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895069#M353582</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1906"&gt;@finans_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you so much once again for your quickly reply, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; . Here is my challenge: the subsets will be overlapping. For example, sampleid 111 will be a combination of 112 and 113. I could not figure out how to create sample IDs without overwriting the existing ones.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One could, without writing macros to split up large data sets, write a data step which created (potentially) multiple observations from one original observation. So if an original observation winds up in 112 and 111, the data step creates two observations, with appropriate sample IDs. Then you sort this data by SampleID and then run your PROC MEANS and PROC REG. And then no splitting of the data set and recombining is needed, and no macros are needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For PROC MEANS (but not PROC REG as far as I know) you could also use MULTILABEL formats for this (&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n13dhme6o4ut3en1u8e58r16b3zf.htm" target="_self"&gt;example&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not have time to help you write such code at this time, but I'm sure there are plenty of people here who can help you with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This does bring up the interesting problem, if you have 108 regressions, how do you use these in some logical way? What is the point of generating 108 regressions in the first place?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895069#M353582</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-20T14:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895070#M353583</link>
      <description>&lt;P&gt;Thank you so much for your suggestions, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt; . If I could find a way to do the proc reg without splitting the dataset, that will actually be awesome since the splitting and re-combining will take a massive amount of hard disk space. The challenge I have at this point is that some observations will fall under more than one sample ID due to overlapping subsets.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895070#M353583</guid>
      <dc:creator>finans_sas</dc:creator>
      <dc:date>2023-09-20T14:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895080#M353586</link>
      <description>&lt;P&gt;Put 108 WHERE clauses into a character variable in a dataset.&lt;/P&gt;
&lt;P&gt;Either just type them out&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data samples;
  sampleid+1;
  input where $200.;
cards;
corvar1 le 1 and allmdummy le 1 
corvar1 le 1 and allmdummy eq 1
corvar1 le 1 and allmdummy lt 1
corvar1 eq 1 and allmdummy le 1
corvar1 eq 1 and allmdummy eq 1
corvar1 eq 1 and allmdummy lt 1
corvar1 lt 1 and allmdummy le 1
corvar1 lt 1 and allmdummy eq 1
corvar1 lt 1 and allmdummy lt 1 
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or generate them if there is pattern.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then create a macro for the analysis that takes SAMPLEID and WHERE as inputs.&amp;nbsp; The macro could use &amp;amp;WHERE to generate a WHERE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc reg data=have;
  where &amp;amp;where ;
....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So say the macro is named ANAL you could then call it 108 times with code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set samples;
  call execute(cats('%nrstr(%anal)(sampleid=',sampleid,',where=',where,')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro could include PROC APPEND step(s) to aggregate the results into a single dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 15:29:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895080#M353586</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-20T15:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895101#M353592</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1906"&gt;@finans_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you so much for your suggestions, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt; . If I could find a way to do the proc reg without splitting the dataset, that will actually be awesome since the splitting and re-combining will take a massive amount of hard disk space. The challenge I have at this point is that some observations will fall under more than one sample ID due to overlapping subsets.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The DATA step I posted will work fine with overlapping subsets.&amp;nbsp; Each record is output once for each subset it is in.&amp;nbsp; And you could use a macro or whatever to generate the 108 if-then blocks.&amp;nbsp; &amp;nbsp; Then you could run one PROC REG on the dataset, BY SAMPLEID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But yes, it will take lots of disk space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take a look at Tom's suggestion of putting your control data (WHERE expressions) in a dataset, and then using that to drive macro calls to do 108 PROC REG steps.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 17:35:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895101#M353592</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-09-20T17:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895105#M353593</link>
      <description>&lt;P&gt;I'd still like an answer to this: "&lt;SPAN&gt;This does bring up the interesting problem, if you have 108 regressions, how do you use these in some logical way? What is the point of generating 108 regressions in the first place?"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 18:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895105#M353593</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-20T18:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895108#M353596</link>
      <description>Each variable takes the value of 0 or 1.&lt;BR /&gt;&lt;BR /&gt;allmdummy: a dummy variable that takes the value of 0 or 1.&lt;BR /&gt;&lt;BR /&gt;Are these two true? &lt;BR /&gt;&lt;BR /&gt;If so, you're looking for combinations of (0, 1, 0/1) versus 0,1, 0/1) to make all your combinations?</description>
      <pubDate>Wed, 20 Sep 2023 19:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895108#M353596</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-09-20T19:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895109#M353597</link>
      <description>&lt;P&gt;Partial code, without macros, no pulling data set apart and then later combining data sets&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set regsample;
    length sampleid $ 4;
    array corvar(12) corvar1-corvar12;
    do i=1 to 12;
         if corvar(i) le 1 and alldummy le 1 then do;
             sampleid=cats(i,1,1);
             output;
         end;
         if corvar(i) eq 1 and alldummy le 1 then do;
             sampleid=cats(i,2,1);
             output;
         end;
         /* You write the rest, there are only 9 possibilities here, as m=1,2,3 and n=1,2,3 */
    end;
run; 
proc sort data=want;
    by sampleid obsid;
run;
proc reg data=want noprint outest=wanted2 noprint adjrsq;
    by sampleid obsid;    /*obsid is another ID already stored in the dataset*/
    model depvar1 = ind1 ind2 ind3 ind4 / hcc;
run;
proc means data=want;
    by sampleid;
    var intercept ind1 ind2 ind3 ind4 _rsq_ _adjrsq_;
    output out=wanted3 mean = std= t= probt= / autoname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code passes through data set REGSAMPLE once. Your original code (pull data set apart, combine them all together later) passes through REGSAMPLE 108 times.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 19:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895109#M353597</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-20T19:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895127#M353601</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; for this question. Your statement is correct. The combinations will 0, 1, and 0&amp;amp;1 together versus 0, 1, and 0&amp;amp;1 together. I have 12 variables (corvar1 through corvar12), and each corvar takes the values of 0 and 1. And the other dummy, allmdummy, takes the values of 0 and 1 too. I want to be able to run the same regression for every single combination, which amounts to 108. All the possible combinations for the first variable will look like the following:&lt;/P&gt;
&lt;P&gt;corvar1=0 and allmdummy=0,&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;corvar1=0 and&amp;nbsp; allmdummy=1&lt;/P&gt;
&lt;P&gt;corvar1=0 and allmdummy= 0 or 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;corvar1=1 and allmdummy=0,&lt;/P&gt;
&lt;P&gt;corvar1=1 and allmdummy=1&lt;/P&gt;
&lt;P&gt;corvar1=1 and allmdummy= 0 or 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;corvar1=0,1, allmdummy=0,&lt;/P&gt;
&lt;P&gt;corvar1=0,1 allmdummy=1&lt;/P&gt;
&lt;P&gt;corvar1=0,1 allmdummy= 0 or 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, I will be able to create a unique sampleid for each combination and then run proc reg and proc means command for each combination (sampleid). I hope this helps. Please let me know if you have any follow-up questions.&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 20:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895127#M353601</guid>
      <dc:creator>finans_sas</dc:creator>
      <dc:date>2023-09-20T20:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895130#M353602</link>
      <description>Quick clarification: by "0 or 1" and "0,1" I meant that we include all the values where the variable is either 0 or 1, which by definition is all the observations for a given dummy variable.</description>
      <pubDate>Wed, 20 Sep 2023 20:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895130#M353602</guid>
      <dc:creator>finans_sas</dc:creator>
      <dc:date>2023-09-20T20:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895142#M353610</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1906"&gt;@finans_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; for this question. Your statement is correct. The combinations will 0, 1, and 0&amp;amp;1 together versus 0, 1, and 0&amp;amp;1 together. I have 12 variables (corvar1 through corvar12), and each corvar takes the values of 0 and 1. And the other dummy, allmdummy, takes the values of 0 and 1 too. I want to be able to run the same regression for every single combination, which amounts to 108. All the possible combinations for the first variable will look like the following:&lt;/P&gt;
&lt;P&gt;corvar1=0 and allmdummy=0,&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;corvar1=0 and&amp;nbsp; allmdummy=1&lt;/P&gt;
&lt;P&gt;corvar1=0 and allmdummy= 0 or 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;corvar1=1 and allmdummy=0,&lt;/P&gt;
&lt;P&gt;corvar1=1 and allmdummy=1&lt;/P&gt;
&lt;P&gt;corvar1=1 and allmdummy= 0 or 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;corvar1=0,1, allmdummy=0,&lt;/P&gt;
&lt;P&gt;corvar1=0,1 allmdummy=1&lt;/P&gt;
&lt;P&gt;corvar1=0,1 allmdummy= 0 or 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, I will be able to create a unique sampleid for each combination and then run proc reg and proc means command for each combination (sampleid). I hope this helps. Please let me know if you have any follow-up questions.&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a trivial change to the solution I posted earlier.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 21:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895142#M353610</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-20T21:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895143#M353611</link>
      <description>&lt;P&gt;You're approaching inefficiently in my view.&lt;/P&gt;
&lt;P&gt;You should transpose your data such that all of the variables you want to filter by are one variable with another variable holding the variable name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I think you can run two or three regressions using a BY statement instead of macros or loops anywhere.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data should be something like this, with the transpose replicating your data for you. The overlaps are handled with the different multiple regressions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;VariableName VariableValue AllMDummy ........
ColVar1   0  0
ColVar2 1 0
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc reg data=transposed;
by variableName VariableValue;
.....;
run;

proc reg data=transposed;
by variableName VariableValue ALLMDummy;
.....;
run;

proc reg data=originalData;
*NO BY statement, your 0/1 * 0/1 results in all included but use originalData;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1906"&gt;@finans_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; for this question. Your statement is correct. The combinations will 0, 1, and 0&amp;amp;1 together versus 0, 1, and 0&amp;amp;1 together. I have 12 variables (corvar1 through corvar12), and each corvar takes the values of 0 and 1. And the other dummy, allmdummy, takes the values of 0 and 1 too. I want to be able to run the same regression for every single combination, which amounts to 108. All the possible combinations for the first variable will look like the following:&lt;/P&gt;
&lt;P&gt;corvar1=0 and allmdummy=0,&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;corvar1=0 and&amp;nbsp; allmdummy=1&lt;/P&gt;
&lt;P&gt;corvar1=0 and allmdummy= 0 or 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;corvar1=1 and allmdummy=0,&lt;/P&gt;
&lt;P&gt;corvar1=1 and allmdummy=1&lt;/P&gt;
&lt;P&gt;corvar1=1 and allmdummy= 0 or 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;corvar1=0,1, allmdummy=0,&lt;/P&gt;
&lt;P&gt;corvar1=0,1 allmdummy=1&lt;/P&gt;
&lt;P&gt;corvar1=0,1 allmdummy= 0 or 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, I will be able to create a unique sampleid for each combination and then run proc reg and proc means command for each combination (sampleid). I hope this helps. Please let me know if you have any follow-up questions.&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 21:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895143#M353611</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-09-20T21:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895152#M353616</link>
      <description>&lt;P&gt;Thank you so much for sharing this other perspective, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; . I need to think about how it will work with the data. The starting dataset has around 50 million rows of data (another one that I need to apply the same code to has about 250 million).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 00:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895152#M353616</guid>
      <dc:creator>finans_sas</dc:creator>
      <dc:date>2023-09-21T00:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895153#M353617</link>
      <description>&lt;P&gt;Great question, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; ! This is related to the need to show that the results are robust to different ways of measuring the variable of interest and to the different subsamples. Most of them will be a footnote anyways but we need to perform them.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 00:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895153#M353617</guid>
      <dc:creator>finans_sas</dc:creator>
      <dc:date>2023-09-21T00:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro &amp; Nested Do Loop to subset data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895158#M353620</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1906"&gt;@finans_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you so much for sharing this other perspective, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; . I need to think about how it will work with the data. The starting dataset has around &lt;STRONG&gt;50 million&lt;/STRONG&gt; rows of data (another one that I need to apply the same code to has about &lt;STRONG&gt;250 million&lt;/STRONG&gt;).&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's an exciting twist to the story...&amp;nbsp; If you take one of the approaches where you expand the data to have one record per SampleID, with 108 different sampleIDs, do you have a sense of how much that will increase the number of rows? Each record can't be in all 108 samples, so it wouldn't be 50M*108, but could it be 50M*20?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's getting big.&amp;nbsp; I don't work with big data much, but I'd be inclined to try Tom's approach of just running 108 PROC REG steps (one for each subset), rather than expanding the data into billions of rows.&amp;nbsp; And hopefully you've got enough memory...&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 01:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-amp-Nested-Do-Loop-to-subset-data/m-p/895158#M353620</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-09-21T01:35:55Z</dc:date>
    </item>
  </channel>
</rss>

