BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mmjohnson
Calcite | Level 5

Hi,

 

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?

 

Thanks,

Mickie

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;
PG

View solution in original post

5 REPLIES 5
data_null__
Jade | Level 19
30*8=240 not 180
Rick_SAS
SAS Super FREQ

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;

PGStats
Opal | Level 21

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;
PG
Ludwig61
Fluorite | Level 6

A non-STAT solution:

 

DATA shuffle ;

  SET subjectlist ;

  rand_position = RAND('UNIFORM') ;

RUN ;

 

PROC SORT DATA=shuffle ;

  BY rand_position ;

RUN ;

 

DATA grouped_subjects ;

  SET shuffle ;

  group_id = CEIL(_N_ / 30) ;

RUN ;

Happy provider of untested code
Ksharp
Super User

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;

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!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 6186 views
  • 4 likes
  • 6 in conversation