<?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: help on rolling regressions needed in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46965#M12555</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can establish a 60 row (60 month) array.&amp;nbsp; The first 60 months of your data go into this array, and then are written out to make data for the first 5-year window.&amp;nbsp; Then the next 12 months can be read in, overwriting rows 1 through 12 of the array (i.e. replacing year 1 data with year 6 data).&amp;nbsp; At that point write out the full array again, yielding data for the 2nd windows.&amp;nbsp; Read another 12 months into rows 13-24 (replacing year 2 data with year 7 data), and the write out the 3rd 60-month window.&amp;nbsp; Et Cetera.&amp;nbsp; No subsequent sorting is required, which (in combination with making a data VIEW instead of a data FILE) should make things faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (keep=id endyear endmo y x1 x2)/ view=want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array vars {60,3}&amp;nbsp; /*60 rows for Y, x1 and x2 */;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do n=1 by 1 until (last.id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have (keep=id date y x1 x2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; row=mod(n-1,60)+1;&amp;nbsp;&amp;nbsp; /* for N=1 .. 60 , row=1..60, then N=61==&amp;gt;row=1, N=62==&amp;gt;row=2 etc. */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; vars{row,1}=y;&amp;nbsp; vars{row,2}=x1;&amp;nbsp; vars{row}=x{3};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if n&amp;gt;=60 and mod(n,12)=0 then do;&amp;nbsp; ** If we are at least at obs 60 and it is divisible by 12 ... **;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; endyear=year(date);&amp;nbsp; endmo=month(date);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do row=1 to 60;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y=vars{I,1}; x1=vars{I,2} x2=vars{I,3};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc reg data=want noproint outest=regout;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id endyear endmo;&lt;/P&gt;&lt;P&gt;&amp;nbsp; model y=x1 x2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now you might be concerned that while the data for the first window (year-year5) will have 60 rows in chronological order, not all windows will (for instance for the second window, the data will be ordered year6, year2 ... year5).&amp;nbsp; But PROC REG gives the same result no matter the order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if you do care, then, instead of the "do row=1 to 60" block, you can do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do J=N-59 to N;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row=mod(J-1,60)+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y=vars(row,1};&amp;nbsp; x1=vars(row,2};&amp;nbsp; x2=vars{row,3);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now even though WANT is a data VIEW and not a data FILE, this can take a long time.&amp;nbsp; It would likely to be a good deal faster if you could use the DATA step to make rolling sum-of-squares-and-cross-products, which can be read by PROC REG.&amp;nbsp; Not only is less data passed from one sep to the next, but making a rolling SSCP in the data step ought to be faster.&amp;nbsp; I'm working on a paper to show this.&amp;nbsp; Hoping to present it at NESUG 2012&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Aug 2012 03:08:14 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2012-08-23T03:08:14Z</dc:date>
    <item>
      <title>help on rolling regressions needed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46961#M12551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to do a rolling time-series regression in order to test my regression model. I found a suitable example related to this (link below). The idea is to make the monthly regression go in 5-year loops, iterating 1 year forward at a time. My regression is of following type: Identity= meanHML meanMOM. Dates I have in form 1990-07, 1990-08...until 2008-12. If someone could help me modify the code suitable, I would be happy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Rolling_Calculations"&gt;http://www.sascommunity.org/wiki/Rolling_Calculations&lt;/A&gt; &lt;/P&gt;&lt;DIV class="mcePaste" id="_mcePaste" style="position: absolute; width: 1px; height: 1px; overflow: hidden; top: 0px; left: -10000px;"&gt;﻿&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 16:47:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46961#M12551</guid>
      <dc:creator>carbs</dc:creator>
      <dc:date>2012-02-06T16:47:59Z</dc:date>
    </item>
    <item>
      <title>help on rolling regressions needed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46962#M12552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I am not sure about your question, but I did notice that in your code above you have:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; %&lt;STRONG&gt;&lt;EM&gt;lowcase&lt;/EM&gt;&lt;/STRONG&gt;(&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%substr&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;(&amp;amp;date,&lt;/SPAN&gt;&lt;STRONG style="background-color: white; font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;STRONG style="background-color: white; font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;4&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;))= year &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%then&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; year_date=1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *Don't know if should put something here?;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%else&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; year_date=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;You may not place a comment or other statement between the %IF and its %ELSE.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 06:29:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46962#M12552</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2012-02-07T06:29:50Z</dc:date>
    </item>
    <item>
      <title>help on rolling regressions needed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46963#M12553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks for the hint. However, I decided to change to approach away from macros, since it was quite difficult for me to understand. I've edited the original question to a new form.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 11:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46963#M12553</guid>
      <dc:creator>carbs</dc:creator>
      <dc:date>2012-02-07T11:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: help on rolling regressions needed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46964#M12554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could someone help me out with this rolling regression issue? I've tried to modify the code found from sascommunity.org/wiki but unsuccesfully. Here's what I've wrote, I know it's not correct but at least a starting point..I have the data readily sorted by date (dataset tt). I hope someone would be able to modify the code to a more sensible diection. Thanks!! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;&lt;SPAN id="mce_marker"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 10pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; nmonths=60;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; expanded(drop = nn);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 10pt;"&gt;length&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; span $ &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;13&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; tt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 10pt;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; nn = &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 10pt;"&gt;to&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; &amp;amp;nmonths;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;span = catx(&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 10pt;"&gt;'-'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;, put(intnx(&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 10pt;"&gt;'month'&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;1990&lt;/STRONG&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;07&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;,nn-&amp;amp;nmonths),&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: teal; font-size: 10pt;"&gt;yymm6.&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;, put(intnx(&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 10pt;"&gt;'month'&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;2008&lt;/STRONG&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;12&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;,nn-&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;),&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: teal; font-size: 10pt;"&gt;yymm6.&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="color: black; background: white; font-size: 10pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 10pt;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="color: black; background: white; font-size: 10pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 10pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: red; font-size: 10pt;"&gt;*Re&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;-&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: teal; font-size: 10pt;"&gt;order.&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;proc sort data=expanded;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 10pt;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; span date;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: red; font-size: 10pt;"&gt;*Finally&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;, run all of the regressions independently in a single &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: teal; font-size: 10pt;"&gt;step;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: teal; font-size: 10pt;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;proc reg data=expanded noprint outest=regout;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 10pt;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; span;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: red; font-size: 10pt;"&gt;model&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt; Identity = meanHML meanMOM;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: &amp;amp;quot;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 21:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46964#M12554</guid>
      <dc:creator>carbs</dc:creator>
      <dc:date>2012-02-07T21:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: help on rolling regressions needed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46965#M12555</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can establish a 60 row (60 month) array.&amp;nbsp; The first 60 months of your data go into this array, and then are written out to make data for the first 5-year window.&amp;nbsp; Then the next 12 months can be read in, overwriting rows 1 through 12 of the array (i.e. replacing year 1 data with year 6 data).&amp;nbsp; At that point write out the full array again, yielding data for the 2nd windows.&amp;nbsp; Read another 12 months into rows 13-24 (replacing year 2 data with year 7 data), and the write out the 3rd 60-month window.&amp;nbsp; Et Cetera.&amp;nbsp; No subsequent sorting is required, which (in combination with making a data VIEW instead of a data FILE) should make things faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (keep=id endyear endmo y x1 x2)/ view=want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array vars {60,3}&amp;nbsp; /*60 rows for Y, x1 and x2 */;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do n=1 by 1 until (last.id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have (keep=id date y x1 x2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; row=mod(n-1,60)+1;&amp;nbsp;&amp;nbsp; /* for N=1 .. 60 , row=1..60, then N=61==&amp;gt;row=1, N=62==&amp;gt;row=2 etc. */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; vars{row,1}=y;&amp;nbsp; vars{row,2}=x1;&amp;nbsp; vars{row}=x{3};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if n&amp;gt;=60 and mod(n,12)=0 then do;&amp;nbsp; ** If we are at least at obs 60 and it is divisible by 12 ... **;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; endyear=year(date);&amp;nbsp; endmo=month(date);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do row=1 to 60;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y=vars{I,1}; x1=vars{I,2} x2=vars{I,3};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc reg data=want noproint outest=regout;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id endyear endmo;&lt;/P&gt;&lt;P&gt;&amp;nbsp; model y=x1 x2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now you might be concerned that while the data for the first window (year-year5) will have 60 rows in chronological order, not all windows will (for instance for the second window, the data will be ordered year6, year2 ... year5).&amp;nbsp; But PROC REG gives the same result no matter the order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if you do care, then, instead of the "do row=1 to 60" block, you can do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do J=N-59 to N;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row=mod(J-1,60)+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y=vars(row,1};&amp;nbsp; x1=vars(row,2};&amp;nbsp; x2=vars{row,3);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now even though WANT is a data VIEW and not a data FILE, this can take a long time.&amp;nbsp; It would likely to be a good deal faster if you could use the DATA step to make rolling sum-of-squares-and-cross-products, which can be read by PROC REG.&amp;nbsp; Not only is less data passed from one sep to the next, but making a rolling SSCP in the data step ought to be faster.&amp;nbsp; I'm working on a paper to show this.&amp;nbsp; Hoping to present it at NESUG 2012&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Aug 2012 03:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/help-on-rolling-regressions-needed/m-p/46965#M12555</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2012-08-23T03:08:14Z</dc:date>
    </item>
  </channel>
</rss>

