UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS Code Fragments
Within Subjects Anova with Time Varying Covariates

Data Wide;
  input sub group dv1 dv2 dv3 cv1 cv2 cv3 ;
cards;
1 1  3  4  7  3 1 2
2 1  6  8 12  9 3 1
3 1  7 13 11 11 8 4
4 1  0  3  6  6 2 1
5 2  5  6 11  7 8 3
6 2 10 12 18 15 9 5
7 2 10 15 15 14 8 6
8 2  5  7 11  9 2 8
;
Run;

title '1. GLM, CONSTANT' ;
proc glm data=wide;
  class group;
  model dv1-dv3 = group cv1 / solution ;
  repeated trial 3;
run;

Data Narrow;
  Set Wide;
  dv = dv1; cva=cv1; cvb= cv1; trial = 1; output;
  dv = dv2; cva=cv1; cvb= cv2; trial = 2; output;
  dv = dv3; cva=cv1; cvb= cv3; trial = 3; output;
Run;

proc print;
run;

title '2. MIXED CONSTANT (COMPARE TO SAS GLM)';
proc mixed data=Narrow;
  class sub group trial;
  model dv = group trial group*trial cva trial*cva;
  repeated trial / subject = sub(group) type=cs;
run;

title '2. MIXED CONSTANT (COMPARE TO SPSS MANOVA)';
proc mixed data=Narrow;
  class sub group trial;
  model dv = group trial group*trial cva ;
  repeated trial / subject = sub(group) type=cs;
run;

title '6. MIXED TIME VARYING';
proc mixed data=Narrow;
  class sub group trial;
  model dv = group trial group*trial cvb ;
  repeated trial / subject = sub(group) type=cs;
run;

* Winer example with time varying covariates;
options ls=80;

* winer, page 803.  see also winer p. 806. ;
Data Wide;
  input sub group cv yield1 yield2;
cards;
1 1  3 10  8
2 1  5 15 12
3 1  8 20 14
4 1  2 12  6
5 2  1 15 10
6 2  8 25 20
7 2 10 20 15
8 2  2 15 10
;
Run;

title '1. GLM, CONSTANT' ;
proc glm data=wide;
  class group;
  model yield1 yield2 = group cv / solution ;
  repeated trial;
run;

Data Narrow;
  Set Wide;
  dv = yield1; trial = 1; output;
  dv = yield2; trial = 2; output;
Run;

proc print;
run;

title '2. MIXED CONSTANT (like SAS GLM, WITH TRIAL by CV interaction)';
proc mixed data=Narrow;
  class sub group trial;
  model dv = group trial group*trial cv trial*cv;
  repeated trial / subject = sub(group) type=cs;
run;

title '3. MIXED CONSTANT (like SPSS MANOVA, NO Trial by CV Interaction)';
proc mixed data=Narrow;
  class sub group trial;
  model dv = group trial group*trial cv ;
  repeated trial / subject = sub(group) type=cs;
run;

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California