<?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 add subset data step by step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891921#M352319</link>
    <description>Thank you both! I'm testing out my code, but cannot make it work. Just not good at iteration, especially when it's in macro.</description>
    <pubDate>Thu, 31 Aug 2023 12:58:32 GMT</pubDate>
    <dc:creator>lichee</dc:creator>
    <dc:date>2023-08-31T12:58:32Z</dc:date>
    <item>
      <title>How to add subset data step by step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891850#M352294</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wanted to examine data with subset cohort included step by step. For example, there are five cohorts, A-E, and I wanted to run regression with the first cohort, and then I would run regression with an additional cohort each time. How can I conduct this using MACRO or iteration efficiently?&lt;/P&gt;
&lt;P&gt;proc reg data=mydata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;model dependent=independents;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;where cohort in ('A');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc reg data=mydata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;model dependent=independents;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;where cohort in ('A','B');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc reg data=mydata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;model dependent=independents;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;where cohort in ('A','B','C');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc reg data=mydata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;model dependent=independents;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;where cohort in ('A','B','C','D');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc reg data=mydata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;model dependent=independents;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;where cohort in ('A','B','C','D','E');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would think I can probably start with creating the list like below:&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;select distinct quote(cohort) into :st_list separated by ','&lt;BR /&gt;from mydata;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 04:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891850#M352294</guid>
      <dc:creator>lichee</dc:creator>
      <dc:date>2023-08-31T04:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to add subset data step by step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891868#M352300</link>
      <description>As part of your plan,  note that the IN operator does not require commas.  You could shoot for (for example):&lt;BR /&gt;&lt;BR /&gt;where cohort in ('A' 'B' 'C')&lt;BR /&gt;&lt;BR /&gt;That will simplify subsequent programming. &lt;BR /&gt;&lt;BR /&gt;Also note, SQL automatically creates &amp;amp;sqlobs which would be 5 in this case (number of items extracted).  So your program could continue by writing a macro along these lines:&lt;BR /&gt;&lt;BR /&gt;%macro regloop;&lt;BR /&gt;%local n;&lt;BR /&gt;%do n=1 %to &amp;amp;sqlobs;&lt;BR /&gt;&lt;BR /&gt;Then have the macro generate PROC REG, using the first &amp;amp;n items from &amp;amp;stlist.&lt;BR /&gt;&lt;BR /&gt;Definitely needs some details worked out, but that should give you a way to approach the problem.</description>
      <pubDate>Thu, 31 Aug 2023 05:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891868#M352300</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-08-31T05:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to add subset data step by step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891912#M352316</link>
      <description>&lt;P&gt;I assume that the code you showed works. What would a macro do that this code does not do? You mention "iteration", what would be iterating?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also question the statistical methodology here about adding cohort after cohort into the data in sequential fashion like you are doing. I would imagine a better way to see the impact of cohort is to add it into the model so that you can have different intercepts and/or different slopes for the different cohorts.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 12:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891912#M352316</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-31T12:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to add subset data step by step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891921#M352319</link>
      <description>Thank you both! I'm testing out my code, but cannot make it work. Just not good at iteration, especially when it's in macro.</description>
      <pubDate>Thu, 31 Aug 2023 12:58:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891921#M352319</guid>
      <dc:creator>lichee</dc:creator>
      <dc:date>2023-08-31T12:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to add subset data step by step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891956#M352337</link>
      <description>Thank you Paige! I know it's statistically not correct way to add cohort after cohort into regression analysis. But I'm just giving a quick and simple example.</description>
      <pubDate>Thu, 31 Aug 2023 14:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891956#M352337</guid>
      <dc:creator>lichee</dc:creator>
      <dc:date>2023-08-31T14:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to add subset data step by step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891957#M352338</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/430334"&gt;@lichee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I'm testing out my code, but cannot make it work. Just not good at iteration, especially when it's in macro.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its still not clear to me what "iteration" you mean, where in this problem is there "iteration"? Please describe in detail.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 15:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891957#M352338</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-31T15:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to add subset data step by step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891967#M352343</link>
      <description>I'd like to see how to add cohorts one by one given the list of cohorts. Thanks!</description>
      <pubDate>Thu, 31 Aug 2023 15:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891967#M352343</guid>
      <dc:creator>lichee</dc:creator>
      <dc:date>2023-08-31T15:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to add subset data step by step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891981#M352347</link>
      <description>&lt;P&gt;OK, here's a bit more of what a macro could look like.&amp;nbsp; All of this would follow the code you originally posted.&amp;nbsp; It assumes you remove the comma and use a blank as the "separated by" character.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro regloop;
   %local n subset;
   %do n=1 to &amp;amp;sqlobs;
      %let subset = &amp;amp;subset %scan(&amp;amp;stlist, &amp;amp;n);
      proc reg data=mydata;
        model dependent = independents;&lt;BR /&gt;       where cohort in (&amp;amp;subset);&lt;BR /&gt;      run;
   %end;&lt;BR /&gt;%mend region;&lt;BR /&gt;&lt;BR /&gt;%regloop&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will generate 5 PROC REGs, just like you have.&amp;nbsp; But the cohort values (and the actual number of PROC REGs) will depend on the data set you are processing.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 15:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-subset-data-step-by-step/m-p/891981#M352347</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-08-31T15:48:12Z</dc:date>
    </item>
  </channel>
</rss>

