I am working to understand some of the differences between SAS and R (using the fable, forecasting, or basic stats packages) to be able to run the same model in SAS and R. After being unable to replicate a more complex model, I tried to run a basic ARIMA (1,1,1) and work my way up. I know that this is not the right model for my data, the point of this is not to fit a model, rather to get the same forecasted values using SAS and R.
However, I am not understanding the SAS outcome - although the data has seasonality, I have not indicated that to SAS. But the forecasted values make me think that something is happening in SAS that I don't know about. Interestingly, when I add an intercept to my R model, I get similar values as the SAS model where I specify no intercept.
I would appreciate any insight anyone has into this! I have read through a lot of R and SAS documentation, but have not found anything that sheds light on why this would happen. I have attached a screenshot of the forecasted values in SAS, R without an intercept, and R with an intercept. Thanks!
proc arima data=cld;
identify var=lgs1(1) nlag=13 minic scan esacf
estimate p=(1)q=(1) input=(sspben)
noint method=ml plot;
forecast lead=61 interval=month id=month alpha=0.05 out=s1out;
R (fable) code without an intercept (with an intercept, replace ~0 with ~1):
model(arima = ARIMA(lgs1 ~ 0+ sspben +pdq(1,1,1)
select(month, lgs1, forecast)
in fact you fit a SARIMAX model (Seasonal ARIMA with regressors).
Can you try the statespace representation of your SARIMAX model?
You need PROC SSM (StateSpace Modelling) for that.
See here for an example :
SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation
SAS/ETS 15.3 User's Guide
The SSM Procedure
Example 34.6 Model with Multiple ARIMA Components
Hi @sbxkoenk thanks for your response!
Interesting... so the proc arima command will identify seasonality even if you don't specify it? I thought that it would only incorporate seasonality if I were to add e.g. (12)., to indicate the seasonality.
I am not understanding how to incorporate the arima into the SSM when I the input variable is in my dataset. I have tried a few versions to run the SSM (not too familar with them / SAS) and get different errors. For example, I get the error message "The name in the TREND statement must not be an analysis variable, such as a variable from the input data set."
proc ssm data=cld;
id date interval=month;
trend sspben(arma(p=1 d=1 q=1));
model lgs1= sspben;
In the linked example, it looks like their trend statements are introducing new variables with arima models?
I thought that it would only incorporate seasonality if I were to add e.g. (12)., to indicate the seasonality.
That's how it works indeed.
Why do you think PROC ARIMA (SAS/ETS) is modelling seasonality when not asked to do so?
For a seasonal model on monthly data, you will indeed have to put that (12) explicitly.
Like here :
/*-- Seasonal Model for the Airline Series --*/ proc arima data=seriesg; identify var=xlog(1,12); estimate q=(1)(12) noint method=ml; forecast id=date interval=month printall out=b; run;
With respect to statespace representation of SARIMAX using PROC SSM, I will check about including regressors (input variables).
ARIMAX model class specifications can be tedious and matching specs and results in two different languages is not easy. Even if matching specs are created, the numbers may not match because the iterative model fitting phase may lead to different parameter estimates and then, in turn, different forecasts. Therefore, for this illustration I am choosing a data set, Box & Jenkins's Series R, and a slightly simplified version of the Box & Tiao model (Example 4 in the ARIMA doc SAS Help Center: An Intervention Model for Ozone Data). Please see the attached files, ozone.txt gives the R code, and ozone.sas gives the SAS code. Essentially, the R spec:
fit = dt %>% model(arima=ARIMA(ozone~ 0 + x1 + pdq(0,0,1) + PDQ(0,1,1), method="ML"))
identify var=ozone(12) crosscorr=(x1(12)) noprint;
estimate q=(1)(12) input=(x1) noint method=ml;
The parameter estimates and forecasts match well.
Model: LM w/ ARIMA(0,0,1)(0,1,1) errors
ma1 sma1 x1
0.3043 -0.6932 -1.2404
s.e. 0.0612 0.0662 0.2219
sigma^2 estimated as 0.6328: log likelihood=-245.25
AIC=498.5 AICc=498.7 BIC=511.77
1: package ‘fable’ was built under R version 4.3.1
2: package ‘fabletools’ was built under R version 4.3.1
> fit %>% forecast(new_data=extra)
# A fable: 12 x 5 [1M]
# Key: .model 
.model date ozone .mean x1
<chr> <mth> <dist> <dbl> <dbl>
1 arima 1973 Jan N(1.6, 0.63) 1.55 1
2 arima 1973 Feb N(2.1, 0.69) 2.07 1
3 arima 1973 Mar N(2.7, 0.69) 2.72 1
4 arima 1973 Apr N(3, 0.69) 3.05 1
5 arima 1973 May N(3.4, 0.69) 3.40 1
6 arima 1973 Jun N(3.4, 0.69) 3.44 1
7 arima 1973 Jul N(4, 0.69) 4.01 1
8 arima 1973 Aug N(4.2, 0.69) 4.18 1
9 arima 1973 Sep N(3.6, 0.69) 3.58 1
10 arima 1973 Oct N(2.9, 0.69) 2.90 1
11 arima 1973 Nov N(2, 0.69) 1.97 1
12 arima 1973 Dec N(1.5, 0.69) 1.45 1
|Maximum Likelihood Estimation|
Pr > |t|
|Forecasts for variable ozone|
|Obs||Forecast||Std Error||95% Confidence Limits|
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.