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
How many obs you need to backward moving ?
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
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
When I run the last data step, the log writes the following error message:
ERROR: The ARRAYNAME
The error message refers to the last line (i.e. pct_20=pctl(20,of a{*});). Should this be changed somehow?
Esben
I have no problem. did you lost _temporary_ ?
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
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
Thanks a lot! It works perfectly.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.