Hi everyone !
I have a time series of 200 observations with one variable of interest, y. With a window of size 100, I have to estimate the model y=lag(y), compute variance and skewness for each sample. I also want to save all those values in a dataset (one column per indicator, one row per sample).
Could you please help me ? 😅
I had to make a few assumptions about your questions, but this would be my best guess answer:
/* generate dummy data t, y(t) */
data have;
call streaminit(76876);
do _n_ = 1 to 200;
t + 1;
y + rand("NORMAL");
output;
end;
stop;
run;
/* Arrange the data into windows */
data sets;
set have;
do set = _n_ - 99 to _n_;
if 1 <= set <= 100 then output;
end;
run;
proc sort data = sets; by set t; run;
/* Calculate autoregression estimates */
proc autoreg data=sets outest=est plots=none noprint;
by set;
model y = / nlag=1;
output out=preds residual=res;
run;
/* Compute statistics on original data and residuals for each data window */
proc univariate data=preds noprint;
by set;
var y res;
output out=setstats var=yvar resvar skewness=yskew resskew;
run;
@PGStats thank you very much for taking the time to reply ! I will try your solution 😀
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.