data exercise;
input Subject_ID $ Posttest Treatment $;
cards;
A 24 T
B 26 C
C 25 T
D 44 C
E 45 T
F 24 C
G 25 T
;
run;
PROC TTEST;
class treatment;
var Posttest;
RUN;
data exercise;
input Subject_ID $ Posttest Treatment $;
cards;
A 24 T
B 26 C
C 25 T
D 44 C
E 45 T
F 24 C
G 25 T
;
run;
PROC TTEST;
class treatment;
var Posttest;
RUN;
/*Ttest Macro*/
/*Creates a result sad data set t_test_results*/
/*Find it in a temp folder and click-open it as an excel file*/
%let dataname=sashelp.class;
%let varlist=weight height age;
%let group=sex;
proc ttest data=&dataname;
class &group;
var
&varlist
;
ods output statistics=kaz1 ttests=kaz2 equality=kaz3;
run;
data kaz3b;
set kaz3;
if ProbF < 0.05 then unequal=1;
if unequal=1;
keep Variable unequal;
run;
proc sort;by Variable ;run;
proc sort data=kaz2;by Variable ;run;
data both;
merge kaz2 kaz3b;
by Variable ;
if unequal ne 1 then unequal=0;
flag=0;
if unequal=0 and variances="Equal" then flag=1;
if unequal=1 and variances="Unequal" then flag=1;
if flag=1;
SIG=" ";
if Probt < 0.05 then SIG="*";
keep Variable Probt SIG variances;
run;
data kaz1b;
set kaz1;
jun=_n_;
run;
proc sort;by Variable ;run;
data t_test_results;
merge kaz1b both;
by Variable ;
this=0;
if class = "Diff (1-2)" then this=1;
if this =1 then do;
probt2=probt;
SIG2=SIG;
variances2=variances;
end;
keep Variable Class mean N probt2 sig2 variances2;
run;