BookmarkSubscribeRSS Feed
Lapis Lazuli | Level 10


I have 92 funds in my database. they  are sorted by PCSSP_median. I want to split them in two group (46 low_median and 46 high median). I write this but it does not make equal division 

 proc rank data=PCSSP_sort out=want groups=2;
var PCSSP_median;
ranks deciles;


Diamond | Level 26

PROC RANK will not make groups of equal size when there are ties in the data. So, if you still want equal sizes, you'd have to write code yourself to split up the ties, some into group 1 and some into group 2.

Paige Miller
Super User


Proc sort data=pcssp_sort;
   by pcssp_median;

data want;
   set pcssp_sort;
   group= (_n_ le 92)+1;

Assigns group 1 for smaller values, 2 for larger. May have same value of pcssp_median in both groups depending on where ties in your data occur.

Super User
  • Deciles are groups of percentiles, broken into 10's. Since you're grouping by 2 I would not recommend naming them deciles to avoid confusion.
  • If there are ties then PROC RANK will allocate into the same group - what do you want to happen if there are ties?
data want;;
set PCSSP_sort nobs=_nobs;
RANK = 1 - ( _n_ < (_nobs/2));

Quick brute force method above. 

NOBS captures the number of observations in the dataset.

NOBS/2 is the middle. 

0 => low_median

1 => high_median


If you want it split by the median, PROC RANK is correct. 


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.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 4 in conversation