Help using Base SAS procedures

Stratified Randomization

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Stratified Randomization

I have 3 treatments (A,B,C). I need to build a data set with these treatments and allocate the subject according to a 2:1:2 randomization ratio. I have a sample of 2310 so I just divided the treatments as 924 for treatment A(2/5*2310), 462 for treatment B, and 924 treatment C. 

 

Here is what I have so far:

 

Data treat;
Treatment="A";
Treatment="B";
Treatment="C";
run;
proc surveyselect data=score out=score1
method=SRS
seed=12345678
sampsize=(924 462 924);
strata treatment notsorted;
run;

When I run the code I just get the treatment C for the variable A and B does not show up. Probability of selection is still 0.4 which is not what I want and sample ratio is not really working. 

 

Any help would be greatly appreciated. 


Accepted Solutions
Solution
‎06-12-2018 04:13 PM
Trusted Advisor
Posts: 1,256

Re: Stratified Randomization

Hi @azt5173 and welcome to the SAS Support Communities,

 

Your dataset TREAT will contain only one observation (Treatment="C") because you forgot to write OUTPUT statements after each of the three assignment statements. This explains why A and B do not occur.

 

I don't know what your dataset SCORE looks like, but if you want to randomly assign 2310 subjects to three treatment groups, the GROUPS= option of PROC SURVEYSELECT could be helpful:

 

data subjects;
do subjno=1 to 2310;
  output;
end;
run;

proc surveyselect data=subjects groups=(924 462 924)
out=assignment
seed=12345678;
run;

 

 

You may want to replace the numeric treatment variable GroupID with values 1, 2, 3 by a character variable TREATMENT with values "A", "B", "C" in dataset ASSIGNMENT afterwards (or just assign a format to map 1 --> "A" etc.).

 

The above technique as well as an alternative -- PROC PLAN -- were suggested in replies to a similar question in 2016:

https://communities.sas.com/t5/SAS-Data-Mining-and-Machine/Generate-random-order-within-a-set-of-num...

View solution in original post


All Replies
Solution
‎06-12-2018 04:13 PM
Trusted Advisor
Posts: 1,256

Re: Stratified Randomization

Hi @azt5173 and welcome to the SAS Support Communities,

 

Your dataset TREAT will contain only one observation (Treatment="C") because you forgot to write OUTPUT statements after each of the three assignment statements. This explains why A and B do not occur.

 

I don't know what your dataset SCORE looks like, but if you want to randomly assign 2310 subjects to three treatment groups, the GROUPS= option of PROC SURVEYSELECT could be helpful:

 

data subjects;
do subjno=1 to 2310;
  output;
end;
run;

proc surveyselect data=subjects groups=(924 462 924)
out=assignment
seed=12345678;
run;

 

 

You may want to replace the numeric treatment variable GroupID with values 1, 2, 3 by a character variable TREATMENT with values "A", "B", "C" in dataset ASSIGNMENT afterwards (or just assign a format to map 1 --> "A" etc.).

 

The above technique as well as an alternative -- PROC PLAN -- were suggested in replies to a similar question in 2016:

https://communities.sas.com/t5/SAS-Data-Mining-and-Machine/Generate-random-order-within-a-set-of-num...

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 211 views
  • 3 likes
  • 2 in conversation