BookmarkSubscribeRSS Feed
bayoote
Calcite | Level 5

Hi Everyone,

 

I have a data set and I want to get the accumulative 25%,75%, 50% quantiles for several variables. That is, for every row, I want to get the quantiles for the column including all the data before that row. Anyone knows how to do that?

 

Thanks!

 

2 REPLIES 2
ballardw
Super User

You will likely get a better answer if you provide some example data and what the results for that data would be.

Since quantiles are order statistics there are likely to be some questions.

 

I am guessing at this point as to what you mean/ want. Do you have access to SAS/IML? I have a sneaking suspicion that might be needed or the easiest. If you don't know if you have SAS/IML you can try running this code:

 

Proc product_status;

run;

The log will show SAS modules you currently have installed.

RichardDeVen
Barite | Level 11

How many rows does the data have ?

 

Up to a certain point, one simple approach is to combine N groups of sizes 1 to N over the data and process the combined data using PROC MEANS with a BY statement.

 

Example - 100 rows, creates a 'triangle' of grouped data with 5,050 rows ( N (N+1) / 2 ) 

data have;
  call streaminit(123);
  do row = 1 to 100;
    x = ceil(500*rand('normal', 10, 4));
    output;
  end;
run;

data triangle;
  set have nobs=nobs;
  do group = _n_ to nobs;
    output;
  end;
run;

proc sort data=triangle;
  by group;
run;

proc means noprint data=triangle;
  by group;
  var x;
  output out=accum_quartiles q1=q1 p50=p50 q3=q3;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 347 views
  • 0 likes
  • 3 in conversation