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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 501 views
  • 0 likes
  • 4 in conversation