<?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: Rolling regression using macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412689#M279879</link>
    <description>&lt;P&gt;If I do some manipulation and get the following format:&amp;nbsp; &amp;nbsp;IDNAME&amp;nbsp; &amp;nbsp;Count&amp;nbsp; &amp;nbsp;Variable1&amp;nbsp; &amp;nbsp;Variable2&lt;/P&gt;
&lt;P&gt;Here 'Count' measures the date from 1 to a number based on date of each ID (for example, 120). Each ID has different number of count.&lt;/P&gt;
&lt;P&gt;Now I run a regression of Variable1 on Variable2 using only 6 counts, i.e., 1-6 for the first regression, 2-7 for the second, 3-8,....&lt;/P&gt;
&lt;P&gt;How to write this macro for the regression. I am new to the macro. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc reg data=one noprint outest=results;&lt;/P&gt;
&lt;P&gt;model variable1=variable2;&lt;/P&gt;
&lt;P&gt;by IDNAME count;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Sun, 12 Nov 2017 13:56:33 GMT</pubDate>
    <dc:creator>ZZB</dc:creator>
    <dc:date>2017-11-12T13:56:33Z</dc:date>
    <item>
      <title>Rolling regression using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412679#M279877</link>
      <description>&lt;P&gt;The format of the data set: ID&amp;nbsp; Date Year Month Day&amp;nbsp; Variable1&amp;nbsp; Variable2&lt;/P&gt;
&lt;P&gt;The dataset has the daily observations for each ID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For &lt;STRONG&gt;each ID each month&lt;/STRONG&gt;, I want to run a regression of Variable 1 on variable 2 based on &lt;STRONG&gt;recent 6-month daily observations&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;How to use the macro to run this regression? It is more complicated than the monthly rolling regression.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;If I do some manipulation and get the following format:&amp;nbsp; &amp;nbsp;IDNAME&amp;nbsp; &amp;nbsp;Count&amp;nbsp; &amp;nbsp;Variable1&amp;nbsp; &amp;nbsp;Variable2&lt;/P&gt;
&lt;P&gt;Here 'Count' measures the date from 1 to a number based on date of each ID (for example, 120). Each ID has different number of count.&lt;/P&gt;
&lt;P&gt;Now I run a regression of Variable1 on Variable2 using only 6 counts, i.e., 1-6 for the first regression, 2-7 for the second, 3-8,....&lt;/P&gt;
&lt;P&gt;How to write this macro for the regression. I am new to the macro. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc reg data=one noprint outest=results;&lt;/P&gt;
&lt;P&gt;model variable1=variable2;&lt;/P&gt;
&lt;P&gt;by IDNAME count;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 13:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412679#M279877</guid>
      <dc:creator>ZZB</dc:creator>
      <dc:date>2017-11-12T13:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling regression using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412681#M279878</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13438"&gt;@ZZB&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The format of the data set: ID&amp;nbsp; Date Year Month Day&amp;nbsp; Variable1&amp;nbsp; Variable2&lt;/P&gt;
&lt;P&gt;The dataset has the daily observations for each ID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For &lt;STRONG&gt;each ID each month&lt;/STRONG&gt;, I want to run a regression of Variable 1 on variable 2 based on &lt;STRONG&gt;recent 6-month daily observations&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;How to use the macro to run this regression? It is more complicated than the monthly rolling regression.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks very much!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I doubt someone here will write such a macro for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The general steps, for you to try, are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;select the proper 6 months of data from original data set&lt;/LI&gt;
&lt;LI&gt;perform regression&lt;/LI&gt;
&lt;LI&gt;store results&lt;/LI&gt;
&lt;LI&gt;repeat with next six month period&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sun, 12 Nov 2017 11:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412681#M279878</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-11-12T11:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling regression using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412689#M279879</link>
      <description>&lt;P&gt;If I do some manipulation and get the following format:&amp;nbsp; &amp;nbsp;IDNAME&amp;nbsp; &amp;nbsp;Count&amp;nbsp; &amp;nbsp;Variable1&amp;nbsp; &amp;nbsp;Variable2&lt;/P&gt;
&lt;P&gt;Here 'Count' measures the date from 1 to a number based on date of each ID (for example, 120). Each ID has different number of count.&lt;/P&gt;
&lt;P&gt;Now I run a regression of Variable1 on Variable2 using only 6 counts, i.e., 1-6 for the first regression, 2-7 for the second, 3-8,....&lt;/P&gt;
&lt;P&gt;How to write this macro for the regression. I am new to the macro. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc reg data=one noprint outest=results;&lt;/P&gt;
&lt;P&gt;model variable1=variable2;&lt;/P&gt;
&lt;P&gt;by IDNAME count;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 13:56:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412689#M279879</guid>
      <dc:creator>ZZB</dc:creator>
      <dc:date>2017-11-12T13:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling regression using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412690#M279880</link>
      <description>&lt;P&gt;I don't see where you have asked a specific question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have asked for help writing a macro, but we don't know at what point in the process you are having trouble. Please be specific.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 14:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412690#M279880</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-11-12T14:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling regression using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412698#M279881</link>
      <description>&lt;P&gt;I totally have no idea on writing the macro in this case.&lt;/P&gt;
&lt;P&gt;For example, in the second case, I do not know what is wrong with the following code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro estim&lt;/P&gt;
&lt;P&gt;%do x=6 to %to count;&amp;nbsp; /* count varies for each IDNAME, some ID has a number of 100, some ID is 156 */&lt;/P&gt;
&lt;P&gt;data temp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set one;&lt;/P&gt;
&lt;P&gt;if &amp;amp;x-5&amp;lt;=count&amp;lt;=&amp;amp;x;&lt;/P&gt;
&lt;P&gt;per=&amp;amp;x;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc reg data=temp noprint outest=results;&lt;/P&gt;
&lt;P&gt;model variable1=variable2;&lt;/P&gt;
&lt;P&gt;by IDNAME per;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 16:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412698#M279881</guid>
      <dc:creator>ZZB</dc:creator>
      <dc:date>2017-11-12T16:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling regression using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412706#M279882</link>
      <description>&lt;P&gt;So it would help if you showed the SASLOG as well as the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nevertheless, a few things stand out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;semicolon is needed at the end of&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro estim;&lt;/PRE&gt;
&lt;P&gt;You need to use macro constructs in the %do statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%do x=6 %to &amp;amp;count;&lt;/PRE&gt;
&lt;P&gt;In order for this to work, you have to define what value &amp;amp;count has, I assume this is based upon the number of data points you have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After the last line of code, you need to end the macro with %mend; and then call the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%mend;
%estim&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Nov 2017 17:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412706#M279882</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-11-12T17:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling regression using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412707#M279883</link>
      <description>&lt;P&gt;Thanks! But the problem is how to define the "count", which varies for each ID. Could you give an example of code in this case?&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 17:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412707#M279883</guid>
      <dc:creator>ZZB</dc:creator>
      <dc:date>2017-11-12T17:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling regression using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412747#M279884</link>
      <description>&lt;P&gt;Yet you have written code that does not include the variable ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use PROC SUMMARY to determine the maximum value of count for each ID. You can use the PROC SUMMARY results to determine the value of the macro variable &amp;amp;COUNT. Or you could do this via PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The more I think about it, the more I think you should be doing this without macros, using data step code, PROC SORT and a BY statement in PROC REG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 22:28:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412747#M279884</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-11-12T22:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling regression using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412766#M279885</link>
      <description>&lt;P&gt;1. Start by getting regression running for a single model&lt;/P&gt;
&lt;P&gt;2. Expand your model and run it for three iterations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Look at what's changed between 1 &amp;amp; 2 and that will tell you what you need to change for your model.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can see some examples of this here:&amp;nbsp;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And this is a commonly asked question, so if you search you should find results here or on lexjansen.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 00:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-using-macro/m-p/412766#M279885</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-13T00:36:45Z</dc:date>
    </item>
  </channel>
</rss>

