BookmarkSubscribeRSS Feed
_vichz
Fluorite | Level 6

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 ? 😅

 

2 REPLIES 2
PGStats
Opal | Level 21

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;
PG
_vichz
Fluorite | Level 6

@PGStats  thank you very much for taking the time to reply ! I will try your solution 😀

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Discussion stats
  • 2 replies
  • 1207 views
  • 2 likes
  • 2 in conversation