There is no method available in PROC RANK to ensure that each quantile will contain the same number of observations. When the GROUPS= option is used, the rank is determined by the result of FLOOR(rank*K/(N+1)), as documented in the RANK chapter of the SAS Procedures Guide.
The number of observations falling into each quantile group depends on the values of the ranking variable and the distribution of these values in the input data set. If there are ties, then all of these observations will be ranked with the same value, as determined by the TIES= option. Ties and a skewed distribution of values can produce unequally sized quantile groups. If some other ranking criterion is needed, consider using the DATA step to assign group values based on your own ranking method.
Please see the Full Code section of this article for an example of using DATA step code to assign group values.
Full Code
First, sort your data by the variable to be ranked. Then, in the DATA step, use the NOBS option on the SET statement to obtain the number of observations in the data set. Finally, incorporate the formula that PROC RANK uses to compute groups, but substitute the automatic variable _N_ for the rank, and the value of the NOBS variable for N.
data test;
input x @@;
cards;
0 0 0 0 0 0 1 2 1 2 3 4 3
;
run;
proc sort data=test;
by x;
run;
data ranks;
set test nobs=numobs;
group=floor(_n_*4/(numobs+1));
keep x group;
run;
proc print;
run;
Output
OBS X GROUP
1 0 0
2 0 0
3 0 0
4 0 1
5 0 1
6 0 1
7 1 2
8 1 2
9 2 2
10 2 2
11 3 3
12 3 3
13 4 3