<?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 every 30 obs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-every-30-obs/m-p/866660#M342271</link>
    <description>&lt;P&gt;Thanks for you suggestion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.stocks out =have ; by stock descending date;run;

data have; set have ;
by stock;
if first.stock then n=0;
n+1;
run;

proc sql;
create table full
as select a.stock, a.date , b. date as _date, b.close, b.volume
from have as a left join have as b
on a.stock=b.stock and a.n&amp;lt;=b.n&amp;lt;=a.n+30
order by a.stock,  a.date , b.date;
quit;

proc reg noprint data=full outest=want_test;
by stock date;
    model close = volume;
    output out=want (keep = stock date predicted residual) p=predicted r=residual;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 28 Mar 2023 01:40:03 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2023-03-28T01:40:03Z</dc:date>
    <item>
      <title>Rolling regression every 30 obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-every-30-obs/m-p/866579#M342223</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I use the&amp;nbsp;sashelp.stocks as the input file and I want to run regression of&lt;/P&gt;
&lt;P&gt;Close = Volume&lt;/P&gt;
&lt;P&gt;For a given day, say 27Feb2023, I want to run this regression on 30 rows including&amp;nbsp;27Feb2023.&lt;/P&gt;
&lt;P&gt;The output I want to have is date, stock, predicted value and residual value as in the code below.&lt;/P&gt;
&lt;P&gt;Can you please help?&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc reg noprint data=sashelp.stocks outest=want_test;
by stock;
    model close = volume;
    output out=want (keep = stock date predicted residual) p=predicted r=residual;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 17:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-every-30-obs/m-p/866579#M342223</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2023-03-27T17:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling regression every 30 obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-every-30-obs/m-p/866583#M342226</link>
      <description>&lt;H2&gt;&lt;A href="https://pages.stern.nyu.edu/~adesouza/sasfinphd/index/node25.html" target="_self"&gt;Rolling regressions without macros&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 17:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-every-30-obs/m-p/866583#M342226</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-27T17:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling regression every 30 obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-every-30-obs/m-p/866660#M342271</link>
      <description>&lt;P&gt;Thanks for you suggestion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.stocks out =have ; by stock descending date;run;

data have; set have ;
by stock;
if first.stock then n=0;
n+1;
run;

proc sql;
create table full
as select a.stock, a.date , b. date as _date, b.close, b.volume
from have as a left join have as b
on a.stock=b.stock and a.n&amp;lt;=b.n&amp;lt;=a.n+30
order by a.stock,  a.date , b.date;
quit;

proc reg noprint data=full outest=want_test;
by stock date;
    model close = volume;
    output out=want (keep = stock date predicted residual) p=predicted r=residual;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Mar 2023 01:40:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-regression-every-30-obs/m-p/866660#M342271</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2023-03-28T01:40:03Z</dc:date>
    </item>
  </channel>
</rss>

