Hello! I am trying to assign participants to 3 groups using a discrete uniform "table" distribution. I am wondering if there is a way to add to this code to that I get exactly 200, 200, and 100 participants in each group:
data bios675.uniform (keep=treat);
call streaminit(2822);*Set seed;
p1=200/500; p2=200/500; p3=100/500;*Set probabilities of three treatment groups;
do i=1 to 500; *500 participants;
treat=rand("Table", p1, p2, p3);
output;
end;
run;
I'm wondering if there is somethign I can do like if a group reaches this number, than stop? Or something like that... Thank you!
Keep track of the declining number of needed cases (N1, N2, N3) in each TREAT level, and the declining number of total available subjects:
data want (keep=treat);
call streaminit(2822);*Set seed;
array n {3} (200,200,100);
do available=sum(of n{*}) to 1 by -1;
treat=rand("Table",n1/available,n2/available,n3/available);
output;
n{treat}=n{treat}-1;
end;
run;
Note: It can be shown that even though probabilities change over the course of the assignment process, every observation has an equal probability of being assigned to a given group.
Editted note: initially forgot to put in the streaminit. It's there now.
proc plan seed=17431;
factors group=10 subjid=500 / noprint;
output out=temp;
run;
data want;
set temp;
if subjid in (1:100) then treat=1;
if subjid in (101:300) then treat=2;
if subjid in (301:500) then treat=3;
run;
proc freq data=want;
table group*treat/list;
run;
Keep track of the declining number of needed cases (N1, N2, N3) in each TREAT level, and the declining number of total available subjects:
data want (keep=treat);
call streaminit(2822);*Set seed;
array n {3} (200,200,100);
do available=sum(of n{*}) to 1 by -1;
treat=rand("Table",n1/available,n2/available,n3/available);
output;
n{treat}=n{treat}-1;
end;
run;
Note: It can be shown that even though probabilities change over the course of the assignment process, every observation has an equal probability of being assigned to a given group.
Editted note: initially forgot to put in the streaminit. It's there now.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.