BookmarkSubscribeRSS Feed
thuphammm
Fluorite | Level 6

Hi, I've just done estimating and forecasting using ARIMA, below is my code. I want to do the Hold-out method where I have my test set and my training set separated, then compare the test set with what I forecasted, I want to have both of them on the same graph now. Please help!

 

ods html close;
ods html;

data tesla;
infile "/folders/myfolders/TSLA (1).csv" delimiter=',' firstobs=2;
input date :anydtdte. open high low close adj_close vol;
format date MONYY7.;
informat date MONYY7.;
proc print data=tesla;

ods graphics on;
proc sgplot data=tesla;
series x=date y=open;
Xaxis values=('01Jun2010'd to '01Jun2019'd by year) valuesformat=year4.;
title 'TSLA Opening Price';
run;

proc arima data=tesla;
identify var=open(1);
estimate p=3 q=2 method=ml noconstant; 
forecast lead=12 out=teslaforecast; 
proc print data=teslaforecast;
run;
5 REPLIES 5
ballardw
Super User

To display multiple sorts of values on the same graph the data must be in a single data set. General rule regardless of data sources or type of graph.

 

So the idea is to combine the "forecast" and "actual" data in a manner that has a variable that indicates the source of the data.

You would want to have the same x and y variable names. One way to combine that adds a source variable with the name of the contributing data set.

data combine;
   set dataset1 
        dataset2
        indsname=ds
   ;
   source=ds;
run;

Other approaches could use the "in=invar" data set option and set a desired source value based on the In variables.

Then something like:

proc sgplot data=combined;
   series x=xvar y=yvar / group=sourcevar;
run;
thuphammm
Fluorite | Level 6

Thank you for your help, I think it worked a little bit, I just don't know how to draw a graph from the combined data set.. This is what I put in:

data combine;
   set tesla 
        teslaforecast
        indsname=ds
   ;
   source=ds;
proc print data=combine;
proc sgplot data=combine;
run;

and this is the outcome:

Screen Shot 2021-03-30 at 09.29.42.png

I couldn't get the graph to appear 😞

sbxkoenk
SAS Super FREQ

Hello,

 

It's better to include the log if you want debugging by other community members.

 

Your SGPLOT code is a bit brief. 😉 No wonder you don't get a plot back.

You should at least tell the procedure what it has to plot (with a series statement for example).

 

Cheers,

Koen

 

 

sbxkoenk
SAS Super FREQ

Hello,

 

Just add this to your PROC ARIMA statement

plots=FORECAST(ALL).

This PLOTS option in the PROC ARIMA statement controls the plots produced through ODS Graphics.

 

Have a nice day,

Koen

 

Rick_SAS
SAS Super FREQ

See the article "Highlight forecast regions in graphs", which shows how to get the plot by using PROC ARIMA and to get a similar plot by using PROC SGPLOT.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1120 views
  • 6 likes
  • 4 in conversation