BookmarkSubscribeRSS Feed
grayab
Calcite | Level 5

Hello -

I have a sample of 60 units that need to be randomized to treatment and control (30 and 30).  However, I have several subgroups I want to block on, such that the units within them are randomized within the subgroups. There should be .5 probability of randomization within each block.  I would like an outcome roughly like this:

Group1 (6 units):  3T, 3C

Group2 (10 units): 5T, 5C

Group3 (6 units): 3T, 3C

Group4 (38 units): 19T, 19C

I am not sure how to code for this.  I was thinking of something along these lines, but this doesn't seem to be quite right:

PROC SURVEYSELECT DATA=mysample method = sys rate = 0.5 seed = 11235813 out=OUTFILE outall;

       STRATA Group1 Group2 Group3 Group4;

Run;

DATA assignment; SET OUTFILE;

      SamplingWeight GT 0 THEN GROUP = 'TREATMENT';

      SamplingWeight EQ 0 THEN GROUP = 'CONTROL';

RUN;


A second question is how I should set up my data file to facilitate this.  I currently have binary indicator variables for each subgroup.  How do I write the code to ensure that only the 1s for a given subgroup are randomized within that block?

I realize this is a complex question. I appreciate any suggestions.

Thanks.

5 REPLIES 5
PGStats
Opal | Level 21

Assign a random number R to each unit. Sort your units by Group and R. Take the first 3 units for Group 1 T, the next 3 for Group 1 C, the next 5 for Group 2 T, and so on. The assignment will be perfectly random within each Group.

PG

PG
PGStats
Opal | Level 21

One simple way to do this is with dataset interleaving :

/* Define groups treatments and units, unrandomized */

data units;

input grp trt $ id $ @@;

datalines;

1 C A 1 C B 1 C C

1 T D 1 T E 1 T F

2 C G 2 C H 2 C I 2 C J 2 C K

2 T L 2 T M 2 T N 2 T O 2 T P

;

/* Make sure the order is well defined */

proc sort data=units; by grp trt; run;

/* Assign a random number to every unit */

data randomIds;

call streamInit(233434);

set units;

ran = rand("UNIFORM");

keep grp id ran;

run;

/* Sort random numbers (i.e. randomize units) within every group */

proc sort data=randomIds; by grp ran; run;

/* Interleave units and random assignment */

data assign;

set units;

set randomIds;

drop ran;

run;

proc print data=assign noobs; run;

PG

PG
grayab
Calcite | Level 5

Thank you.  I like this suggestion for its simplicity.  One possibly minor issue with it is that (while I did not explain this above) some of groups have odd numbers of units -- a decision will have to be made as to whether the final unit in those groups is assigned to T or C.  I feel that this introduces some degree of bias.

I wonder if there is a way to use the process you have described above, but to have SAS assign the last unit in the subgroups that have odd numbers of units?

I really appreciate this help.  I am a fairly new SAS user and I have not used it for this purpose before.

PGStats
Opal | Level 21

Remember, YOU define the design in the initial step. So you could have an entry in a group have TRT="D" (instead of "C" or "T") and then drop the unit that ends up randomly assigned to it.

PG

PG
grayab
Calcite | Level 5

gotcha.

Thank you!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 1321 views
  • 3 likes
  • 2 in conversation