<?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 generate a forecast path using data step? in SAS Forecasting and Econometrics</title>
    <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126910#M714</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Should be possible with minor changes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data yyy;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; L2 = L1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; L1 = Xhat;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain Xhat L1 L2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set xxx;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;by group;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; if first.group then group_counter=1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; else group_counter + 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &lt;/STRONG&gt; if &lt;STRONG&gt;group_counter&lt;/STRONG&gt; &amp;lt; 3 then Xhat = X;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else Xhat = beta1 * L1 + beta2 * L2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're working with large amounts of data, you can speed things up a tiny bit by changing the order of the last two statements:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if group_counter &amp;gt; 2 then Xhat = beta1 * L1 + beta2 * L2;&lt;/P&gt;&lt;P&gt;else Xhat = X;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Mar 2013 16:12:44 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2013-03-05T16:12:44Z</dc:date>
    <item>
      <title>How to generate a forecast path using data step?</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126906#M710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, folks:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a simple time series model but not estimated by arima, but I want to generate a forecast path based on historical data and estimated parameters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, the model is given by x=beta1*lag(x)+beta2*lag2(x); obviously the forecast for a given forecast period, say, t+k, should be xhat(t+k)=beta1*xhat(t+k-1)+beta2*xhat(t+k-2), where xhat is the forecast value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wonder if I can use the data step to archieve this goal. The key part is to update the value of xhat iteratively. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a data set with the structure as the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;xxxx;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; T&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; X&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Beta1&amp;nbsp; Beta2&lt;/P&gt;&lt;P&gt;_________________________&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x (1)&amp;nbsp;&amp;nbsp; beta1&amp;nbsp; beta2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x (2)&amp;nbsp;&amp;nbsp;&amp;nbsp; beta1&amp;nbsp;&amp;nbsp; beta2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&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; beta1&amp;nbsp;&amp;nbsp; beta2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&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; beta1&amp;nbsp;&amp;nbsp; beta2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&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; beta1&amp;nbsp;&amp;nbsp;&amp;nbsp; beta2&lt;/P&gt;&lt;P&gt;Basically, if there is historical data, the value of x is the historical value, if not, it is missing and the value of Beta1 and Beta2 are hold at the estimated value for each observation. The task is to generate a series of Xhat. Xhat(T)=beta1*Xhat(t-1)+beta2*Xhat(t-2);, for T=3, Xhat(2)=x(2) and Xhat(1)=x(1). For T&amp;gt;3, we just use lag values of Xhat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data yyy;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set xxxx;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xhat=X;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; l1_xhat0=lag(xhat);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; l2_xhat0=lag(l1_xhat);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; xhat0=beta1*l1_xhat0+beta2*l2_xhat0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; xhat=xhat0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, in the dataset, yyy, the value of xhat is still missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone give me some hints or advice on what the correct way is to do it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jing&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 19:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126906#M710</guid>
      <dc:creator>bigbigben</dc:creator>
      <dc:date>2013-03-04T19:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a forecast path using data step?</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126907#M711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you provide some sample data and, based on that data, the values you want used at each step of the calculation?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 20:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126907#M711</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-03-04T20:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a forecast path using data step?</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126908#M712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's an attempt, possibly a good one at that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data yyy;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; L2 = L1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; L1 = Xhat;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain Xhat L1 L2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set xxx;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if _n_ &amp;lt; 3 then Xhat = X;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else Xhat = beta1 * L1 + beta2 * L2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 22:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126908#M712</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-03-04T22:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a forecast path using data step?</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126909#M713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Astounding:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much. It works very well. If there are different groups of data and different parameter values, and I want to do the same thing for each group, can I simply write the code as:&lt;/P&gt;&lt;P&gt;data yyy;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; L2 = L1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; L1 = Xhat;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain Xhat L1 L2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set xxx;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG&gt; by group;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if _n_ &amp;lt; 3 then Xhat = X;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else Xhat = beta1 * L1 + beta2 * L2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know I am being lazy here, but your input is highly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Jing&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Mar 2013 14:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126909#M713</guid>
      <dc:creator>bigbigben</dc:creator>
      <dc:date>2013-03-05T14:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a forecast path using data step?</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126910#M714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Should be possible with minor changes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data yyy;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; L2 = L1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; L1 = Xhat;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain Xhat L1 L2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set xxx;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;by group;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; if first.group then group_counter=1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; else group_counter + 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &lt;/STRONG&gt; if &lt;STRONG&gt;group_counter&lt;/STRONG&gt; &amp;lt; 3 then Xhat = X;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else Xhat = beta1 * L1 + beta2 * L2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're working with large amounts of data, you can speed things up a tiny bit by changing the order of the last two statements:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if group_counter &amp;gt; 2 then Xhat = beta1 * L1 + beta2 * L2;&lt;/P&gt;&lt;P&gt;else Xhat = X;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Mar 2013 16:12:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/How-to-generate-a-forecast-path-using-data-step/m-p/126910#M714</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-03-05T16:12:44Z</dc:date>
    </item>
  </channel>
</rss>

