BookmarkSubscribeRSS Feed
EsbenVibel
Calcite | Level 5

Hello everybody,

I work with a time series dataset, and I need to compute a backward moving percentile for a time series. How can this be done in SAS? I have considered the EXPAND procedure, but to my knowledge this procedure can only compute a backward moving median (i.e. 50% percentile) using the "MOVMED" statement. How should I proceed if I want to compute a (for example) 20% backward moving percentile using a time window of, say, 250 observations?

Thanks in advance!

Best,

Esben Vibel

8 REPLIES 8
Ksharp
Super User

How many obs you need to backward moving ?

EsbenVibel
Calcite | Level 5

My dataset has approx. 10,000 obs., and I would like to compute 20% backward moving percentiles based on a window of 252 observations.

Best,

Esben

Ksharp
Super User

I am not familiar with proc expand, maybe you can check the documention and find some one option.

And my code make a window of 252 includes the current obs.

data have(drop=i);
do i=1 to 10000;
 x=ranuni(-1);
 output;
 end;
run;
data want;
 set have;
 array a{0:251} _temporary_ ;
 a{mod(_n_,252)}=x;
 pct_20=pctl(20,of a{*});
run;


Ksharp

EsbenVibel
Calcite | Level 5

When I run the last data step, the log writes the following error message: 

ERROR: The ARRAYNAME

  • specification requires a variable based array
  • The error message refers to the last line (i.e. pct_20=pctl(20,of a{*});). Should this be changed somehow?

    Esben

    Ksharp
    Super User

    I have no problem. did you lost _temporary_ ?

    EsbenVibel
    Calcite | Level 5

    I simply copied your code directly into SAS and ran it. I use SAS 9.1; do I need newer version to run the code?

    Esben

    Ksharp
    Super User

    Are you still using sas 9.1?

     
    
    data have(drop=i);
    do i=1 to 10000;
     x=ranuni(-1);
     output;
     end;
    run;
    data want(drop=aa:);
     set have;
     array a{0:251} aa1-aa252 ;
     retain aa: ;
     a{mod(_n_,252)}=x;
     pct_20=pctl(20,of a{*});
    run;
    
    
    
    

    Ksharp

    EsbenVibel
    Calcite | Level 5

    Thanks a lot! It works perfectly.

    What is Bayesian Analysis?

    Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

    Find more tutorials on the SAS Users YouTube channel.

    SAS Training: Just a Click Away

     Ready to level-up your skills? Choose your own adventure.

    Browse our catalog!

    Discussion stats
    • 8 replies
    • 3845 views
    • 1 like
    • 2 in conversation