Programming the statistical procedures from SAS

Proc Mixed, Repeated measures, nesting within sub

Occasional Contributor
Posts: 7

Proc Mixed, Repeated measures, nesting within sub

Hello! I was presented with this model statement today, and am confused why you would nest an individual within a treatment?



data hotties;

input ID trt day time rtemp; 


1 1 3 1 103.6

1 1 3 2 103.6

1 1 4 1 104.2

1 1 4 2 104.6


2 2 3 1 102.1

2 2 3 2 102.6

2 2 4 1 102.2

2 2 4 2 103.6

3 1 3 1 103.1

3 1 3 2 103.5

3 1 4 1 102.9

3 1 4 2 103.2



class ID trt day time;

model rtemp = trt|day|time/ ddfm=satterw;

repeat day/ sub = ID(trt);    <<<<<<<< the sub = ID(trt), this is the part I do not understand what it does or why you would use it in this senario. Any thoughts? The SAS description of sub is to create a block, which is great. But my interpretation of this is that individual is then blocked by treatment, which does not make a whole lot of sense to me. Why would you block by treatment? Or am I interpretting this incorrectly?


Super User
Posts: 10,207

Re: Proc Mixed, Repeated measures, nesting within sub

if your ID is unique ,then you can use 

repeat day/ sub = ID


But if not ,then you have to use 

repeat day/ sub = ID(trt)


repeat day/ sub = ID*trt

to make subject id(strata) is unique.



id trt

1 1

2 1

1 2

2 2

for this kind of data you have to use sub=id(trt) .

Posts: 275

Re: Proc Mixed, Repeated measures, nesting within sub

The syntax

repeated day / subject=id(trt);

corresponds to an experimental design in which each subject (id) is randomly assigned to one level of trt, and multiple observations are made on each id at each level of day. As such, ids are nested within levels of trt: each id belongs to only one level of trt


id(trt) identifies a random effects factor that has one level for each unique combination of id and trt. It does not mean that trt is random; it's just a syntax shortcut.


Alternatively, you could assign each subject a unique id value and use

repeated day / subject=unique_id;

which is the point that @Ksharp is making.


Even with unique values for subjects, I still use the nested syntax because it does a better job of giving me the denominator df that I think are appropriate.


I note that you have time in the MODEL statement. I bet this is a repeated measures factor as well, probably multiple times within each day. If so, your model is wrong, along with your understanding of the MIXED syntax. But that's another topic.


I highly recommend

It will tell you most of what you need to know.


Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation