## How to grouping the values?

Solved
Frequent Contributor
Posts: 75

# How to grouping the values?

Hallo, can someone please help how can I group the coef? I have a data set which look like this:

id                                    coef

...........

It has n rows. The coef is sorted and I would like to splits them into 10 groups. The first group would have the first n/10 highest coef and the last group would have the latest n/10 lowest coef.

Thank you so much!

Accepted Solutions
Solution
‎11-27-2012 06:36 PM
Posts: 5,543

## Re: How to grouping the values?

Two ways to do this :

proc ranks data=have out=want groups=10 descending;
var coef;
ranks group;
run;

/* Assuming data have is sorted by coef */

data want;
set have nobs=ntot;
group= 10 - floor((_n_*10)/(ntot-1));
run;

PG

PG

All Replies
Solution
‎11-27-2012 06:36 PM
Posts: 5,543

## Re: How to grouping the values?

Two ways to do this :

proc ranks data=have out=want groups=10 descending;
var coef;
ranks group;
run;

/* Assuming data have is sorted by coef */

data want;
set have nobs=ntot;
group= 10 - floor((_n_*10)/(ntot-1));
run;

PG

PG
Frequent Contributor
Posts: 75

## Re: How to grouping the values?

Thank you. it works great

🔒 This topic is solved and locked.