Hi Everyone,
I want to do a process similar to finding moving percentile.
However, for each record, I want to look back 500 records (excluding the current record) and extract the value of the 475th largest record (it is not the same as 95 percentile in SAS).
I prefer this way to percentile since it is comparable with other software I use and I can control the value better.
So for the data below, for the first record, the value-475 should be 476.
Thank you for your help.
HHC
data have;
do value=1 to 1000;output; end;
;run;
You mean look forward ?
data have; do value=1 to 1000; output; end; ; run; data want; set have nobs=nobs; array x{99999} _temporary_; do i=_n_+1 to min(nobs,_n_+499); set have(rename=(value=v)) point=i; x{i}=v; end; _25th=largest(25,of x{*}); call missing(of x{*}); drop i v; run;
Xia Keshan
I think you mean 25th largest?
data have;
do value=1 to 1000;
output;
end;
;
run;
data want;
array t(0:499) _temporary_;
set have;
t(mod(_n_,500))=value;
if _n_>499 then
_25th=largest(25,of t(*));
run;
Haikuo
Hi,
It is almost what I want.
However, the first record value for _25th should be 476.
file want should look like:
value _25th
1 476
2 477
...
HHC
This?
data want;
array t(0:499) _temporary_;
set have;
t(mod(_n_,500))=value;
if _n_>499 then do;
_25th=largest(25,of t(*));
n+1;
output;
end;
drop value;
rename n=value;
run;
Yes it is the what I want. But I want to keep the original 1000 records. Right now the last 499 records are gone.
If I have to do DO LOOP through this code, each time, the data is reduced by 499.
HHC
You mean look forward ?
data have; do value=1 to 1000; output; end; ; run; data want; set have nobs=nobs; array x{99999} _temporary_; do i=_n_+1 to min(nobs,_n_+499); set have(rename=(value=v)) point=i; x{i}=v; end; _25th=largest(25,of x{*}); call missing(of x{*}); drop i v; run;
Xia Keshan
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.