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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.