07-19-2016 02:23 PM - edited 07-19-2016 02:43 PM
I have an experiment with 6 conditions and 180 participants. I want to generate numbers to randomly assign participants to one of the conditions. In the end I would like to get the same number of people (30) per condition. Is there a sas function that I can use to randomly generate integers from 1 to 6 to assign to them 180 participants?
07-19-2016 02:47 PM
8 does not evenly divide into 180. You say you want 30 people per condition, but that requires 240 participants.
At any rate, one way to do what you want is to use PROC PLAN in SAS/STAT software. There is a Getting Started example that shows exactly what you ask. Change the macro values in the following code to get random assignment for any number of participants and treatments.
%let numUnits = 180; /* number of participants */ %let numTreat = 8; /* number of treatments */ data Unrandomized; do Unit=1 to &numUnits; Treatment = 1 + mod(Unit-1, &numTreat); output; end; run; /* Randomize the design */ proc plan seed=27371; factors Unit=&numUnits; output data=Unrandomized out=Randomized; run; proc sort data=Randomized; by Unit; run; proc freq data=Randomized; tables Treatment; run;
07-19-2016 03:10 PM
You can also use proc surveyselect with the groups= option:
%let numUnits = 180; /* number of participants */ %let numTreat = 6; /* number of treatments */ data units; do Unit = 1 to &numUnits; output; end; run; proc surveyselect data=units groups=&numTreat seed=86787 out=assignedUnits(rename=groupId=treatment); run; proc freq data=assignedUnits ; tables treatment; run;
07-19-2016 03:49 PM
A non-STAT solution:
DATA shuffle ;
SET subjectlist ;
rand_position = RAND('UNIFORM') ;
PROC SORT DATA=shuffle ;
BY rand_position ;
DATA grouped_subjects ;
SET shuffle ;
group_id = CEIL(_N_ / 30) ;
07-19-2016 09:40 PM
Here are two distribution you can use.
data _null_; call streaminit(1234); do i=1 to 10; rank=ceil(6*rand('uniform')); put i=1 rank=; end; run; /*****************/ data _null_; call streaminit(1234); do i=1 to 10; rank=rand('table',1/6,1/6,1/6,1/6,1/6,1/6); put i=1 rank=; end; run;