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-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

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