BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

Hi Everyone,

I want to calculate moving quartile not include current record.

This post below is the moving including current record.

https://communities.sas.com/message/173630

I thought it could be a{1:252} but clearly, it doesn't work.

Can you fix it for me or can you suggest other method?

Thank you,

HHC

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Change the order perhaps? I would also set pct_20 to missing if you don't have 252 records so a full moving window.

data want2;

set have;

array a{0:251} aa1-aa252 ;

retain aa: ;

pct_20=pctl(20,of a(*));

  a{mod(_n_,252)}=x;

  if _n_ <252 then pct_20=.;

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

Change the order perhaps? I would also set pct_20 to missing if you don't have 252 records so a full moving window.

data want2;

set have;

array a{0:251} aa1-aa252 ;

retain aa: ;

pct_20=pctl(20,of a(*));

  a{mod(_n_,252)}=x;

  if _n_ <252 then pct_20=.;

run;

hhchenfx
Barite | Level 11

Thank you, Reeza for correcting it.

HHC

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 466 views
  • 0 likes
  • 2 in conversation