简体   繁体   中英

Simulating ARMA/ARIMA time series processes in SAS

I've been trying to find the simplest way to generate simulated time series datasets in SAS. I initially was experimenting with the LAG operator, but this requires input data, so is proabably not the best way to go. (See this question: SAS: Using the lag function without a set statement (to simulate time series data.) )

Has anyone developed a macro or dataset that enables time series to be genereated with an arbitrary number of AR and MA terms? What is the best way to do this?

To be specific, I'm looking to generate what SAS calls an ARMA(p,q) process, where p denotes the autoregressive component (lagged values of the dependent variable), and q is the moving average component (lagged values of the error term).

Thanks very much.

I have developed a macro to attempt to answer this question, but I'm not sure whether this is the most efficient way of doing this. Anyway, I thought it might be useful to someone:

%macro TimeSeriesSimulation(numDataPoints=100, model=y=e,outputDataSetName=ts, maxLags=10);

data &outputDataSetName (drop=j);
array lagy(&maxlags) _temporary_;
array lage(&maxlags) _temporary_;
/*Initialise values*/

e = 0;
y=0;
t=1;
do j = 1 to 10;
lagy(j) = 0;
lage(j) = 0;
end;

output;

do t = 2 to &numDataPoints;  /*Change this for number of observations*/

    /*SPECIFY MODEL HERE*/
    e = rannorm(-1);  /*Draw from a N(0,1)*/
    &model; 

    /*Update values of lags on the moving average and autoregressive terms*/
    do j = &maxlags-1 to 1 by -1;  /*Note you have to do this backwards because otherwise you cascade the current value to all past values!*/
        lagy(j+1) = lagy(j);
        lage(j+1) = lage(j);
    end;
    lagy(1) = y;
    lage(1) = e;

    output;
end;
run;

%mend;

/*Example 1:  Unit root*/
%TimeSeriesSimulation(numDataPoints=1000, model=y=lagy(1)+e)

/*Example 2:  Simple process with AR and MA components*/
%TimeSeriesSimulation(numDataPoints=1000, model=y=0.5*lagy(1)+0.5*lage(1)+e)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM