Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit molestiae mollitia laudantium assumenda nam eaque, excepturi, soluta, perspiciatis cupiditate sapiente, adipisci quaerat odio voluptates consectetur nulla eveniet iure vitae quibusdam? Excepturi aliquam in iure, repellat, fugiat illum voluptate repellendus blanditiis veritatis ducimus ad ipsa quisquam, commodi vel necessitatibus, harum quos a dignissimos.
Close Save changesHelp F1 or ? Previous Page ← + CTRL (Windows) ← + ⌘ (Mac) Next Page → + CTRL (Windows) → + ⌘ (Mac) Search Site CTRL + SHIFT + F (Windows) ⌘ + ⇧ + F (Mac) Close Message ESC
We now turn our focus from randomly sampling a subset of observations from a data set to that of generating a random assignment of treatments to experimental units in a randomized, controlled experiment. The good news is that the techniques used to sample without replacement can easily be extended to generate such random assignment plans.
It's probably a good time to remind you of the existence of the PLAN procedure. As I mentioned earlier, due to time constraints of the course and the complexity of the PLAN procedure, we will not use it to accomplish any of our random assignments. You should be aware, however, of its existence should you want to explore it on your own in the future.
Suppose we are interested in conducting an experiment so that we can compare the effects of two drugs (A and B) and one placebo on headache pain. We have 30 subjects enrolled in our study but need to determine a plan for randomly assigning 10 of the subjects to treatment A, 10 of the subjects to treatment B, and 10 of the subjects to the placebo. The following program does just that for us. That is, it creates a random assignment for 30 subjects in a completely randomized design with one factor having 3 levels:
DATA exper1; DO Unit = 1 to 30; OUTPUT; END; RUN; DATA random1; set exper1; random=ranuni(27407349); RUN; PROC SORT data=random1; by random; RUN; PROC FORMAT; value trtfmt 1 = 'Placebo' 2 = 'Drug A' 3 = 'Drug B'; RUN; DATA random1; set random1; if _N_ le 10 then group=1; else if _N_ gt 10 and _N_ le 20 then group=2; else if _N_ gt 20 then group=3; format group trtfmt.; RUN; PROC PRINT data = random1 NOOBS; title 'Random Assignment for CRD with One Factor'; RUN
Okay, let's first launch and run the SAS program, so you can review the resulting output to convince yourself that the code did indeed generate the desired treatment plan. You should see that 10 of the subjects were randomly assigned to treatment A, 10 to treatment B, and 10 to the placebo.
Now, let's walk ourselves through the program to make sure we understand how it works. The first DATA step merely uses a simple DO loop to create a temporary data set called exper1 that contains one observation for each of the experimental units (in our case, the experimental units are subjects). The only variable in the data set, unit, contains an arbitrary label 1, 2, . 30 assigned to each of the experimental units.
The remainder of the code generates a random assignment. To do so, the code from Example 34.5 is simply extended. That is:
Note! The randomization list created here contains information that is potentially damaging to the success of the whole study if it ended up in the wrong hands. That is, blinding would be violated. It is a better (and more common) practice to keep separate master lists that associate unit with the subject's name, and group numbers with treatment names. In many national trials, it is common to have statisticians also blinded from the master list, producing a "triple-blind" trial. I formatted the treatment here just for illustration purposes only.
To create a random assignment for a completely randomized design with two factors, you can just modify the IF statement in the previous example. The following program generates a random assignment of treatments to 30 subjects, in which Factor A has 2 levels and Factor B has 3 levels (and hence 6 treatments). The code is similar to the code from the previous example except the IF statement now divides the 30 subjects into 6 treatment groups and (arbitrarily) assigns the levels of factors A and B to the groups:
DATA random2; set exper1; random=ranuni(4901); RUN; PROC SORT data=random2; by random; RUN; DATA random2; set random2; if _N_ le 5 then do; factorA = 1; factorB = 1; end; else if _N_ gt 5 and _N_ le 10 then do; factorA = 1; factorB = 2; end; else if _N_ gt 10 and _N_ le 15 then do; factorA = 1; factorB = 3; end; else if _N_ gt 15 and _N_ le 20 then do; factorA = 2; factorB = 1; end; else if _N_ gt 20 and _N_ le 25 then do; factorA = 2; factorB = 2; end; else if _N_ gt 25 and _N_ le 30 then do; factorA = 2; factorB = 3; end; RUN; PROC PRINT data = random2; title 'Random Assignment for CRD with Two Factors'; RUN;
First, my apologies for the formatting that makes the IF-THEN-ELSE statement a little difficult to read. I needed to format it as such so that I could easily capture the image of the program for you.
Again, it's probably best if you first launch and run the SAS program, so you can review the resulting output to convince yourself that the code did indeed generate the desired treatment plan. You should see that five of the subjects were randomly assigned to the A=1, B=1 group, five to the A=1, B=2 group, five to the A=1, B=3 group, and so on.
Then, if you compare the code to the code from the previous example, the only substantial difference you should see is the difference between the two IF statements. As previously mentioned, the IF statement here divides the 30 subjects into 6 treatment groups and (arbitrarily) assigns the levels of factors A and B to the groups:
Thus far, our random assignments have not involved dealing with a blocking factor. As you know, it is natural in some experiments to block some of the experimental units together in an attempt to reduce unnecessary variability in your measurements that might otherwise prevent you from making good treatment comparisons. Suppose, for example, that your workload would prevent you from making more than nine experimental measurements in a day. Then, it would be a good idea then to treat the day as a blocking factor. The following program creates a random assignment for 27 subjects in a randomized block design with one factor having three levels.
DATA exper2 (drop = j); DO block = 1 to 3; DO j = 1 to 9; if block = 1 then do; unit = j; output; end; else if block = 2 then do; unit = j + 9; output; end; else if block = 3 then do; unit = j + 18; output; end; END; END; RUN; PROC PRINT data=exper2; title 'EXPER2: Definition of Experimental Units'; RUN; DATA random3; set exper2; random=ranuni(7214508); RUN; PROC SORT data=random3; by block random; RUN; DATA random3; set random3; by block; if first.block then k=0; else k=k+1; if k in (0,1,2) then trt=1; else if k in (3,4,5) then trt=2; else if k in (6,7,8) then trt=3; retain k; RUN; PROC PRINT data=random3 noobs; title 'Random Assignment for RBD: Sorted in BLOCK-TRT Order'; RUN; PROC SORT data=random3; by block unit; RUN; PROC PRINT data=random3 noobs; title 'Random Assignment for RBD: Sorted in BLOCK-UNIT Order'; RUN;
Again, my apologies about the formatting that makes the program a little more difficult than usual to read. I needed to format it as such so that I could easily capture the image of the program for you.
It's probably going to be best if you first launch and run the SAS program, so you can first review the contents of the initial exper2 data set: