BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yelena
Fluorite | Level 6

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).

Assume I have this data:

 

 

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;

 

 

 

Also, suppose the estimated coefficients are: beta = 0.9996 and alpha = -1 .

I need to create (by hand) a new variable, named predicted (which  should be the same as yhat), that is calculated as follows:

 

 

 

data p_test;
set test;

beta = 0.9996;

alpha = -1;

 

predicted = beta*x - alpha*(lag(z) - beta*lag(x));



run;

 

 

 

But I cannot do it for the last two dates. The thing is that if lag(z) is missing, I should tell SAS to use lag(predicted). How to do it?

The predicted values should be equal to yhat as shown below:

 

yhat                   Date          x z beta   alpha predicted
0.9995547997 01/31/2019 1 0 0.9996 -1 .
0.9995547998 02/28/2019 2 1 0.9996 -1 0.9996
1.9995547998 03/31/2019 3 2 0.9996 -1 1.9996
2.9995547998 04/30/2019 4 3 0.9996 -1 2.9996
3.9995547998 05/31/2019 5 . 0.9996 -1 3.9996
4.9991095996 06/30/2019 6 . 0.9996 -1 .
5.9986643994 07/31/2019 7 . 0.9996 -1 .

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

Something like this ?

 

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_>1 then predicted=predicted - alpha*error;

    error=coalesce(Z, predicted) - beta*X;
run;

View solution in original post

2 REPLIES 2
gamotte
Rhodochrosite | Level 12

Hello,

 

Something like this ?

 

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_>1 then predicted=predicted - alpha*error;

    error=coalesce(Z, predicted) - beta*X;
run;
yelena
Fluorite | Level 6

Hello gamotte, thank you for the valuable input. You helped me very much! I appreciate it! Yelena

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 942 views
  • 1 like
  • 2 in conversation