SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
dzurov
Fluorite | Level 6

Hello 

 

I would like to use a given statistical time series function to forecast a variable (y) from a specific date forward (e.g. starting from April 1st 2021). The y variable has the actual data while y_forecast is the estimate based on a function. The function needs to use the lag of the predicted variable (y_forecast) from April 1st 2021 forward. Also, I need to compare the y_forecast to y and determine the variance.

 

In my below attempt I have not been able to generate any values for the forecast period. 

data data;
input date date9. y x;
format date date9.;
cards;
26MAR2021 2.41 1.791
27MAR2021 2.34 1.783
28MAR2021 2.46 1.874
29MAR2021 2.52 1.867
30MAR2021 2.55 1.901
31MAR2021 2.50 1.851
01APR2021 2.61 1.920
02APR2021 2.65 1.932
03APR2021 2.69 1.944
04APR2021 2.74 1.951
;
run;
data model;
set data;

x_lag = lag(x);
x_chg = dif(x); 
y_lag = IFN(Date le '31MAR2021'd ,lag(y),lag(y_forecast));
y_chg_lag = IFN(Date le '31MAR2021'd ,lag(y) - lag2(y), lag(y_forecast) - lag2(y_forecast));

bx1 = 0.2;
bx2 = 0.4;
bc0 = 0.1;
by1 = 0.3;

y_forecast = y_lag + bx1 * x_lag * x_chg + bx2 + bc0 + by1 * y_chg_lag;
variance = y - y_forecast;
run;

 Any thoughts how to achieve this are appreciated. Thanks.

5 REPLIES 5
sbxkoenk
SAS Super FREQ

Hello,

 

Why aren't you using one of the many procedures SAS offers for forecasting (=extrapolating dependent variable time series into the future)?

Do you have SAS/ETS or SAS Econometrics or Forecast Server or Visual Forecasting?

 

Thanks,

Koen

dzurov
Fluorite | Level 6
I don't believe I have those available.
sbxkoenk
SAS Super FREQ

Hello @dzurov ,

 

Which version of SAS are you running?

Submit

%PUT &=sysvlong4;

to find out (look in the LOG).

If you have SAS 9.4 Mx (Maintenance Level something), then submit:

proc setinit; run;
proc product_status; run;

to find out if you have SAS/ETS or SAS Forecast Server.

 

If you have SAS VIYA (VIYA 3.5 or VIYA 4), then submit :

cas;                 /* connect to CAS session */
 
proc cas;
   getLicensedProductInfo;
quit;

to find out if you have SAS/ETS or SAS Econometrics or SAS Visual Forecasting.


Doing the same with a data step will be a pale imitation of real forecasting (where you correctly take autocorrelation into account).

 

See also this blog :

How to find release and licensing information in SAS Viya?
By @Rick_SAS  on The DO Loop February 28, 2022

https://blogs.sas.com/content/iml/2022/02/28/release-license-sas-viya.html

 

Thanks,

Koen

dzurov
Fluorite | Level 6

I'm on version, 9.04 according to the statement below 

 

%PUT &=sysvlong4;

 

I was hoping my objective can be achieved with some other (stats) procedure instead of a data step, since the data step does not seem to remember the prior value of the y_forececast variable. 

sbxkoenk
SAS Super FREQ

Try something like this ( auto-regression ).

 

proc autoreg data=sashelp.citiday;
   model SNYDJCM = / nlag=1 method=ml;
run;

Koen

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 5 replies
  • 930 views
  • 0 likes
  • 2 in conversation