<?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: Forecast using AUTOREG by hand in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Forecast-using-AUTOREG-by-hand/m-p/630663#M186722</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    format Date MMDDYY10.;
    informat Date MMDDYY10.;
    input Date x z;
    datalines;
1/31/2019 1 0
2/28/2019 2 1
3/31/2019 3 2
4/30/2019 4 3
5/31/2019 5 .
6/30/2019 6 .
7/31/2019 7 .
;
run;

data p_test;
    set test;
    retain error 0;

    beta = 0.9996;
    alpha = -1;

    predicted = beta*x;
    if _N_&amp;gt;1 then predicted=predicted - alpha*error;

    error=coalesce(Z, predicted) - beta*X;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 09 Mar 2020 15:27:08 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2020-03-09T15:27:08Z</dc:date>
    <item>
      <title>Forecast using AUTOREG by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forecast-using-AUTOREG-by-hand/m-p/628929#M185904</link>
      <description>&lt;P&gt;I need to produce the out-of-sample forecast using AUTOREG by hand (meaning that I don't need to update the coefficients every time I change my data).&lt;/P&gt;&lt;P&gt;Assume I have this data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test;

FORMAT Date MMDDYY10.;

INFORMAT Date MMDDYY10.;

INPUT Date x z;

DATALINES;

 

1/31/2019 1 0

2/28/2019 2 1

3/31/2019 3 2

4/30/2019 4 3

5/31/2019 5 .

6/30/2019 6 .

7/31/2019 7 .

　



RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, suppose the estimated coefficients are:&amp;nbsp;beta = 0.9996 and alpha&amp;nbsp;= -1 .&lt;/P&gt;&lt;P&gt;I need to create (by hand)&amp;nbsp;a new variable, named&amp;nbsp;predicted (which&amp;nbsp; should be the same as yhat), that is calculated as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data p_test;
set test;

beta = 0.9996;

alpha = -1;

 

predicted = beta*x - alpha*(lag(z) - beta*lag(x));



run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I cannot do it for&amp;nbsp;the last two dates. The thing is that if lag(z) is&amp;nbsp;missing, I should tell SAS to use lag(predicted). How to do it?&lt;/P&gt;&lt;P&gt;The predicted values should be equal to yhat as shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yhat&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x&amp;nbsp;z&amp;nbsp;beta&amp;nbsp;&amp;nbsp; alpha&amp;nbsp;predicted&lt;BR /&gt;0.9995547997&amp;nbsp;01/31/2019&amp;nbsp;1&amp;nbsp;0&amp;nbsp;0.9996&amp;nbsp;-1&amp;nbsp;.&lt;BR /&gt;0.9995547998&amp;nbsp;02/28/2019&amp;nbsp;2&amp;nbsp;1&amp;nbsp;0.9996&amp;nbsp;-1&amp;nbsp;0.9996&lt;BR /&gt;1.9995547998&amp;nbsp;03/31/2019&amp;nbsp;3&amp;nbsp;2&amp;nbsp;0.9996&amp;nbsp;-1&amp;nbsp;1.9996&lt;BR /&gt;2.9995547998&amp;nbsp;04/30/2019&amp;nbsp;4&amp;nbsp;3&amp;nbsp;0.9996&amp;nbsp;-1&amp;nbsp;2.9996&lt;BR /&gt;3.9995547998&amp;nbsp;05/31/2019&amp;nbsp;5&amp;nbsp;.&amp;nbsp;0.9996&amp;nbsp;-1&amp;nbsp;3.9996&lt;BR /&gt;4.9991095996&amp;nbsp;06/30/2019&amp;nbsp;6&amp;nbsp;.&amp;nbsp;0.9996&amp;nbsp;-1&amp;nbsp;.&lt;BR /&gt;5.9986643994&amp;nbsp;07/31/2019&amp;nbsp;7&amp;nbsp;.&amp;nbsp;0.9996&amp;nbsp;-1&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 21:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forecast-using-AUTOREG-by-hand/m-p/628929#M185904</guid>
      <dc:creator>yelena</dc:creator>
      <dc:date>2020-03-02T21:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Forecast using AUTOREG by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forecast-using-AUTOREG-by-hand/m-p/630663#M186722</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    format Date MMDDYY10.;
    informat Date MMDDYY10.;
    input Date x z;
    datalines;
1/31/2019 1 0
2/28/2019 2 1
3/31/2019 3 2
4/30/2019 4 3
5/31/2019 5 .
6/30/2019 6 .
7/31/2019 7 .
;
run;

data p_test;
    set test;
    retain error 0;

    beta = 0.9996;
    alpha = -1;

    predicted = beta*x;
    if _N_&amp;gt;1 then predicted=predicted - alpha*error;

    error=coalesce(Z, predicted) - beta*X;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Mar 2020 15:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forecast-using-AUTOREG-by-hand/m-p/630663#M186722</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-03-09T15:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Forecast using AUTOREG by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forecast-using-AUTOREG-by-hand/m-p/630684#M186731</link>
      <description>&lt;P&gt;Hello gamotte, thank you for the valuable input. You helped me very much! I appreciate it! Yelena&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 17:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forecast-using-AUTOREG-by-hand/m-p/630684#M186731</guid>
      <dc:creator>yelena</dc:creator>
      <dc:date>2020-03-09T17:25:19Z</dc:date>
    </item>
  </channel>
</rss>

