turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- block randomization

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-02-2014 09:07 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to grayab

05-02-2014 10:18 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to grayab

05-02-2014 11:03 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PGStats

05-02-2014 11:29 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to grayab

05-02-2014 11:42 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PGStats

05-02-2014 11:44 PM

gotcha.

Thank you!