Using SAS 9.4
I am running the following code to randomize 273 units into 3 groups with 91 units per groups. However, is it possible to set up the distribution in such a way that every 50 units is evenly distributed among the 3 groups?
meaning the first 50 units would have group 1-17 units, group 2-17 units, group 3-16 units. Thank you for any help
data Unrandomized;
do unit=1 to 273;
if (unit <= 91) then Group=1;
else if (91 < unit <= 182) then Group=2;
else Group=3;
output;
end;
run;
/* Randomize the design */
proc plan seed=22042;
factors unit=273;
output data=Unrandomized out=Randomized;
run;
proc sort data=Randomized;
by unit;
proc print data=Randomized;
run;
One way to randomly assign units to groups is the GROUPS= option in PROC SURVEYSELECT.
For example, this code creates 3 equal (or near-equal) size groups for each batch of 50 observations.
data UnRandomized; do unit=1 to 273; if (unit <= 50) then Batch=1; else if (unit <= 100) then Batch=2; .... output; end; run; proc surveyselect data=UnRandomized groups=3 seed=123 out=randomGroups; strata Batch; run; proc freq data=randomGroups; tables Batch*groupID; run;
One way to randomly assign units to groups is the GROUPS= option in PROC SURVEYSELECT.
For example, this code creates 3 equal (or near-equal) size groups for each batch of 50 observations.
data UnRandomized; do unit=1 to 273; if (unit <= 50) then Batch=1; else if (unit <= 100) then Batch=2; .... output; end; run; proc surveyselect data=UnRandomized groups=3 seed=123 out=randomGroups; strata Batch; run; proc freq data=randomGroups; tables Batch*groupID; run;
This blog post by @Rick_SAS shows how to use the RandContingency function to control both the row and column sums (the Batch and Group sums in your example):
Simulate contingency tables with fixed row and column sums in SAS
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.