BookmarkSubscribeRSS Feed
sasphd
Lapis Lazuli | Level 10

Hello 

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;
run;

thanks

3 REPLIES 3
PaigeMiller
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
ballardw
Super User

Crude:

Proc sort data=pcssp_sort;
   by pcssp_median;
run;

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

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.

Reeza
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));
run;

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. 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 562 views
  • 0 likes
  • 4 in conversation