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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Multiple Linear Regression in SAS

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.

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