Help using Base SAS procedures

How to grouping the values?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 75
Accepted Solution

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
Respected Advisor
Posts: 4,651

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

View solution in original post


All Replies
Solution
‎11-27-2012 06:36 PM
Respected Advisor
Posts: 4,651

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.

Need further help from the community? Please ask a new question.

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