<?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: Need to do OLS Regression on previous observations in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158166#M8262</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;Thanks for the information. I believe I left out a key piece of information. Some of the companies have more than 6 years of data. For example, ABC may have ten years of data from 2000-2009. Therefore, I need to run multiple regressions. One for 2005 on 2000-2004 data. A second for 2006 on 2001-2005 data. A third for 2007 on 2002-2006 data, and so on. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I may be misunderstanding something; but will your suggestion of using BY values and counters still work?&amp;nbsp; I believe I am having trouble visualizing how to increment the BY counter through each 5 year iteration. For example, if I have a counter that creates a BY group for 2000-2004 to do a regression for 2005, can I use a loop and change the value for 2000's revenue data to not be included in the 2006 regression while including 2005's data for the 2006 regression?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks so much for the help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 20 Dec 2014 15:50:20 GMT</pubDate>
    <dc:creator>DThorn</dc:creator>
    <dc:date>2014-12-20T15:50:20Z</dc:date>
    <item>
      <title>Need to do OLS Regression on previous observations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158163#M8259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone, &lt;/P&gt;&lt;P&gt;I have data on businesses, the year, and that businesses revenues for each year like below:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Header 1&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Header 2&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Header 3&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Business&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Year&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Revenues&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;ABC&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;100000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ABC&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;100025&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ABC&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2002&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;100035&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ABC&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2003&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;148520&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ABC&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2004&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;132454&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ABC&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2005&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;456214&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ACME&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1996&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;154741&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;BBB&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1998&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;45214&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;BBB&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;25632&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to write code that will do the following:&lt;/P&gt;&lt;P&gt;1) Perform OLS regression by each company but using the last five years of data. For example, the regression for ABC in 2005 would make the DV the revenues for years 2000-2004 and the sole IV the year variable. I know how to do this in excel, but I want to automate everything into SAS so I am looking for help. The larger purpose is to get the standard error of the year beta coefficient and then divide it by the average revenues for those five years. This is used as a measure of uncertainty in the field I research.&lt;/P&gt;&lt;P&gt;2) I will need to be able to output this standard beta coefficient into a data table (assuming I would use an output command) and then merge it back into other datasets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Other Notes: &lt;/P&gt;&lt;P&gt;1) As shown in the table above, not all businesses have at least 6 years of data. However, if there are not five years of prior data, then no regression needs to be run.&lt;/P&gt;&lt;P&gt;2) If it helps, I have been able to get my data to look like this: However, I do not believe I can run a regression this way. I believe I need rows of observations.&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Header 1&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Header 2&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Header 3&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Header 4&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Header 5&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Header 6&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Header 7&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Firm&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Year&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Year -1 Revenues&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Year -2 Revs&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Year -3 Revs&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Year -4 Revs&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Year -5 Revs&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ACME&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2005&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;132454&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;148520&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;100035&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;100025&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;100000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for all help/hints.&lt;/P&gt;&lt;P&gt;-David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Dec 2014 20:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158163#M8259</guid>
      <dc:creator>DThorn</dc:creator>
      <dc:date>2014-12-19T20:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need to do OLS Regression on previous observations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158164#M8260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's one way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Sort your data by Business and DESCENDING YEAR&lt;/P&gt;&lt;P&gt;2 (or 3). In a data step identify the 5 years of records available for regression analysis using BY value and counters.&lt;/P&gt;&lt;P&gt;3 (or 2). Subset only firms that have 5/6 years + (*depends on order)&lt;/P&gt;&lt;P&gt;4. Run regression using by variables and you'll get a single table with all coefficients for all companies/years.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Steps 2/3 can probably be done in a single SQL step if you're familiar with SQL and don't mind a bigger proc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And yes, your data needs to be in the format you have for table 1, not table 2. You can use a proc transpose to transform it, or a data step.&lt;/P&gt;&lt;P&gt;Though you can do steps 1/2/3 easily in that form but how do you know what years go with what values? If that's not important you can fairly easily transpose and do steps1-3 in your transpose step. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Dec 2014 02:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158164#M8260</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-12-20T02:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need to do OLS Regression on previous observations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158165#M8261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use the following code to get the unique combination of &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;Business&lt;/SPAN&gt; and Year. then use call execute to invoke proc reg to go through all your data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have out=temp nodupkey;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by &lt;SPAN style="line-height: 1.5em; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;Business&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; Year;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;set temp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;call execute(........)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Xia Keshan&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Dec 2014 13:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158165#M8261</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-12-20T13:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need to do OLS Regression on previous observations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158166#M8262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;Thanks for the information. I believe I left out a key piece of information. Some of the companies have more than 6 years of data. For example, ABC may have ten years of data from 2000-2009. Therefore, I need to run multiple regressions. One for 2005 on 2000-2004 data. A second for 2006 on 2001-2005 data. A third for 2007 on 2002-2006 data, and so on. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I may be misunderstanding something; but will your suggestion of using BY values and counters still work?&amp;nbsp; I believe I am having trouble visualizing how to increment the BY counter through each 5 year iteration. For example, if I have a counter that creates a BY group for 2000-2004 to do a regression for 2005, can I use a loop and change the value for 2000's revenue data to not be included in the 2006 regression while including 2005's data for the 2006 regression?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks so much for the help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Dec 2014 15:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158166#M8262</guid>
      <dc:creator>DThorn</dc:creator>
      <dc:date>2014-12-20T15:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need to do OLS Regression on previous observations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158167#M8263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You would have to adjust the following if you are missing years for any company (other than starting and ending years), but this might be an easy way to accomplish what you want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input company $ year revenues;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;a 2002 10&lt;/P&gt;&lt;P&gt;a 2003 50&lt;/P&gt;&lt;P&gt;a 2004 80&lt;/P&gt;&lt;P&gt;a 2005 90&lt;/P&gt;&lt;P&gt;a 2006 110&lt;/P&gt;&lt;P&gt;a 2007 120&lt;/P&gt;&lt;P&gt;a 2008 140&lt;/P&gt;&lt;P&gt;b 2004 58&lt;/P&gt;&lt;P&gt;b 2005 88&lt;/P&gt;&lt;P&gt;b 2006 118&lt;/P&gt;&lt;P&gt;b 2007 138&lt;/P&gt;&lt;P&gt;b 2008 175&lt;/P&gt;&lt;P&gt;c 2004 58&lt;/P&gt;&lt;P&gt;c 2005 88&lt;/P&gt;&lt;P&gt;c 2006 118&lt;/P&gt;&lt;P&gt;c 2007 138&lt;/P&gt;&lt;P&gt;c 2008 175&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have out=need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by company year;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data need (keep=company a_year year revenues);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by company;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain counter .;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array stacka {0:4};&lt;/P&gt;&lt;P&gt;&amp;nbsp; array stackb {0:4};&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain stacka stackb;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.company then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(of stacka{*});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(of stackb{*});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; counter=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; counter+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; stacka{mod(counter,5)} = revenues;&lt;/P&gt;&lt;P&gt;&amp;nbsp; stackb{mod(counter,5)} = year;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if counter gt 4 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a_year=year+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=0 to 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; revenues=stacka{i};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year=stackb{i};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc reg data=need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; model revenues=year;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by company a_year;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Dec 2014 17:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158167#M8263</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-12-20T17:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need to do OLS Regression on previous observations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158168#M8264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If my previous suggestion accomplishes what you want, but you do have to skip groups of years where you are missing one or more years within five year ranges, the following code has an additional if statement to control for that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input company $ year revenues;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;a 2002 10&lt;/P&gt;&lt;P&gt;a 2003 50&lt;/P&gt;&lt;P&gt;a 2004 80&lt;/P&gt;&lt;P&gt;a 2005 90&lt;/P&gt;&lt;P&gt;a 2006 110&lt;/P&gt;&lt;P&gt;a 2007 120&lt;/P&gt;&lt;P&gt;a 2008 140&lt;/P&gt;&lt;P&gt;b 2004 58&lt;/P&gt;&lt;P&gt;b 2005 88&lt;/P&gt;&lt;P&gt;b 2006 118&lt;/P&gt;&lt;P&gt;b 2007 138&lt;/P&gt;&lt;P&gt;b 2008 175&lt;/P&gt;&lt;P&gt;c 2004 58&lt;/P&gt;&lt;P&gt;c 2005 88&lt;/P&gt;&lt;P&gt;c 2006 118&lt;/P&gt;&lt;P&gt;c 2007 138&lt;/P&gt;&lt;P&gt;c 2008 175&lt;/P&gt;&lt;P&gt;c 2010 185&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have out=need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by company year;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data need (keep=company a_year year revenues);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by company;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain counter .;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array stacka {0:4};&lt;/P&gt;&lt;P&gt;&amp;nbsp; array stackb {0:4};&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain stacka stackb;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.company then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(of stacka{*});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(of stackb{*});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; counter=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; counter+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; stacka{mod(counter,5)} = revenues;&lt;/P&gt;&lt;P&gt;&amp;nbsp; stackb{mod(counter,5)} = year;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if counter gt 4 and ((year+1)*5-15 eq sum(of stackb{*})) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a_year=year+1;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=0 to 4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; revenues=stacka{i};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year=stackb{i};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc reg data=need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; model revenues=year;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by company a_year;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Dec 2014 17:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158168#M8264</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-12-20T17:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need to do OLS Regression on previous observations</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158169#M8265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art's code accounts for all of that &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;Basically create a new output group for each set of years that the analysis is running for. e.g&lt;/P&gt;&lt;P&gt;2008 - 2007 to 2003&lt;/P&gt;&lt;P&gt;2007 - 2006 to 2002&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a large dataset this may take up additional space to create but it avoids going into a macro solution.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Dec 2014 19:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Need-to-do-OLS-Regression-on-previous-observations/m-p/158169#M8265</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-12-20T19:10:03Z</dc:date>
    </item>
  </channel>
</rss>

