1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
NOTE: ODS statements in the SAS Studio environment may disable some output features.
73
74 /* pain1.sas (2018 version) */
75 title 'Multivariate repeated measures analysis of the pain data';
76
77 /* Read data from an old .xls spreadsheet */
78 proc import datafile="/folders/myfolders/441s18/Lecture/Pain.xls"
79 out=ouch0 dbms=xls replace;
80 getnames=yes;
NOTE: The import data set has 10 observations and 7 variables.
NOTE: WORK.OUCH0 data set was successfully created.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.02 seconds
cpu time 0.02 seconds
81 proc print;
82
83 /* Dose 1 Dose 2 Dose 3
84 ------ ----- ------
85 Drug 1 Drug1Dose1 Drug1Dose2 Drug1Dose3
86 Drug 2 Drug2Dose1 Drug2Dose2 Drug2Dose3 */
87
88 /* Computing sum and contrast variables in the data step */
NOTE: There were 10 observations read from the data set WORK.OUCH0.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.10 seconds
cpu time 0.10 seconds
89 data ouch1;
90 set ouch0;
91 /* Pairwise differences */
92 d12 = Drug1Dose1-Drug1Dose2; d13 = Drug1Dose1-Drug1Dose3;
93 d14 = Drug1Dose1-Drug2Dose1; d15 = Drug1Dose1-Drug2Dose2;
94 d16 = Drug1Dose1-Drug2Dose3;
95 d23 = Drug1Dose2-Drug1Dose3; d24 = Drug1Dose2-Drug2Dose1;
96 d25 = Drug1Dose2-Drug2Dose2; d26 = Drug1Dose2-Drug2Dose3;
97 d34 = Drug1Dose3-Drug2Dose1; d35 = Drug1Dose3-Drug2Dose2;
98 d36 = Drug1Dose3-Drug2Dose3;
99 d45 = Drug2Dose1-Drug2Dose2; d46 = Drug2Dose1-Drug2Dose3;
100 d56 = Drug2Dose2-Drug2Dose3;
101 /* Marginal means and interactions */
102 Drug1 = mean(of Drug1Dose1--Drug1Dose3);
103 Drug2 = mean(of Drug2Dose1--Drug2Dose3);
104 Dose1 = (Drug1Dose1+Drug2Dose1)/2;
105 Dose2 = (Drug1Dose2+Drug2Dose2)/2;
106 Dose3 = (Drug1Dose3+Drug2Dose3)/2;
107 Drugdiff = drug1-drug2;
108 doseD12 = dose1-dose2; doseD13 = dose1-dose3;
109 doseD23 = dose2-dose3;
110 DrugEffect1 = Drug1Dose1-Drug2Dose1;
111 DrugEffect2 = Drug1Dose2-Drug2Dose2;
112 DrugEffect3 = Drug1Dose3-Drug2Dose3;
113 label DrugEffect1 = 'Drug effect for dose 1'
114 DrugEffect2 = 'Drug effect for dose 2'
115 DrugEffect3 = 'Drug effect for dose 3';
116 int1 = DrugEffect1-DrugEffect2;
117 int2 = DrugEffect1-DrugEffect3;
118 int3 = DrugEffect2-DrugEffect3;
119
NOTE: There were 10 observations read from the data set WORK.OUCH0.
NOTE: The data set WORK.OUCH1 has 10 observations and 37 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
120 proc means data=ouch1 n mean stddev maxdec=3;
121 var Drug1Dose1 -- Drug2Dose3
122 Drug1 Drug2
123 Dose1-Dose3
124 DrugEffect1-DrugEffect3;
125 run;
NOTE: There were 10 observations read from the data set WORK.OUCH1.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.10 seconds
cpu time 0.10 seconds
126
127 /* Test for overall differences, main effects and interaction.
128 Just look at the multivariate output. */
129 ods select MultStat (persist);
130
131 proc reg data=ouch1;
132 title2 'Overall test';
133 model d12-d16 = ;
134 Overall: mtest intercept = 0;
135 run;
136
NOTE: PROCEDURE REG used (Total process time):
real time 0.14 seconds
cpu time 0.12 seconds
137 proc reg data=ouch1;
138 title2 'Main Effect of Drug';
139 model drugdiff = ;
140 Drug: mtest intercept = 0;
141 /* Could have used test or just looked at the t statistic. */
142 run;
143
NOTE: PROCEDURE REG used (Total process time):
real time 0.09 seconds
cpu time 0.07 seconds
144 proc reg;
145 title2 'Main Effect of Dose Level';
146 model dosed12 dosed13 = ;
147 Dose: mtest intercept = 0;
148 run;
149
NOTE: PROCEDURE REG used (Total process time):
real time 0.08 seconds
cpu time 0.07 seconds
150 proc reg data=ouch1;
151 title2 'Drug by Dose Interaction';
152 model int1 int2 = ;
153 Drug_by_Dose: mtest intercept = 0;
154 run;
155
156 /* Follow up, including tests of pairwise difference
157 even though the overall test was not significant. */
158
159 ods select all; /* Turning off the selection */
160
NOTE: PROCEDURE REG used (Total process time):
real time 0.08 seconds
cpu time 0.07 seconds
161 proc means data=ouch1 n mean t probt;
162 title2 'Follow up with matched t-tests';
163 var d12 -- d56
164 dosed12--dosed23
165 int1-int3 ;
166
167 /* Specify transformations of response variables within proc reg
168
169 Dose 1 Dose 2 Dose 3
170 ------ ----- ------
171 Drug 1 Drug1Dose1 Drug1Dose2 Drug1Dose3
172 Drug 2 Drug2Dose1 Drug2Dose2 Drug2Dose3 */
173
174
175 /* Strangely, after the first time I use ods select in a job, it only
176 seems to work when I precede it with quit. ods is a little flaky
177 with SAS University Edition; maybe that's the reason. */
178
179 quit;
NOTE: There were 10 observations read from the data set WORK.OUCH1.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.14 seconds
cpu time 0.13 seconds
179 ! ods select MultStat;
180 proc reg data=ouch0 plots=none;
181 title2 'Specify new response variables within proc reg';
182 model Drug1Dose1 -- Drug2Dose3 = ;
183 Overall: mtest intercept = 0,
184 Drug1Dose1-Drug1Dose2, Drug1Dose1-Drug1Dose3,
185 Drug1Dose1-Drug2Dose1, Drug1Dose1-Drug2Dose2,
186 Drug1Dose1-Drug2Dose3;
187 Drug: mtest intercept = 0,
188 Drug1Dose1+Drug1Dose2+Drug1Dose3
189 - Drug2Dose1-Drug2Dose2-Drug2Dose3;
190 Dose: mtest intercept = 0,
191 Drug1Dose1+Drug2Dose1 - Drug1Dose2-Drug2Dose2,
192 Drug1Dose2+Drug2Dose2 - Drug1Dose3-Drug2Dose3;
193 Interaction: mtest intercept = 0,
194 Drug1Dose1-Drug2Dose1 - Drug1Dose2+Drug2Dose2,
195 Drug1Dose1-Drug2Dose1 - Drug1Dose3+Drug2Dose3;
196 run;
197
198 quit;
NOTE: PROCEDURE REG used (Total process time):
real time 0.17 seconds
cpu time 0.16 seconds
198 ! ods select MultStat GLM.Repeated.WithinSubject.ModelANOVA;
199 proc glm data=ouch0;
200 title2 'Two-factor within cases the easy way';
201 model Drug1Dose1--Drug2Dose3 = ;
202 repeated Drug 2, Dosage 3 / short summary;
203 /* Factor on the right changes fastest (like numbers) */
204 run;
205
206 quit;
NOTE: PROCEDURE GLM used (Total process time):
real time 0.21 seconds
cpu time 0.19 seconds
206 ! ods select MultStat GLM.Repeated.WithinSubject.ModelANOVA;
207 proc glm data=ouch0;
208 title2 'Overall test the easy way';
209 model Drug1Dose1--Drug2Dose3 = ;
210 repeated treatment / short summary;
211 run;
212
213
214
215
216
217
218
219
220 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
233