LOG ON SAS STATEMENTS RELATED TO T-TEST
=======================================
As we covered in class on Monday (10/2/06), PROC TTEST
can be used to get "two-sample pooled-variance t-tests"
using the syntax
PROC TTEST DATA=tmpRsp;
class Gp;
var Resp;
on a SAS dataset tmpRsp which has numeric column "Resp"
and character column "Gp" in the format
Resp Gp
X1 X
X2 X
...
Xn X
Y1 Y
Y2 Y
...
Ym Y
Here X1,...Xn, is the numeric X-sample, and Y1,...,Ym the
numeric Y-sample, and the test is designed to tell whether
the mean for the X's is the same as that for the Y's, when
all observations are assumed normally distributed and
independent with the SAME variances. The SAS output also
includes test values for a "Satterthwaite" t-test that does
NOT require X and Y variances to be equal.
One can also do a PAIRED TTest using the syntax
PROC TTEST TABLES DATA=tmpXY;
PAIRED X*Y;
But to make this PAIRED statement work, you must
have the SAS dataset tmpXY in a two-column format
X Y
X1 Y1
... ...
Xn Yn
There are several ways to go back and forth between
the two types of SAS datasets tmpRsp tmpXY (which do
contain exactly the same information when m=n.)
If you want to try this out, apply it to the Football data!
ALTERNATIVE METHODS FOR CONVERTING tmpXY TO tmpRsp:
(i)
data tmpRspB (keep = Resp Gp) ;
set tmpXY (rename = (X=Resp))
tmpXY (rename = (Y=Resp));
if X = . then Gp = "X";
else Gp = "Y"; run;
(ii)
data tmpRspC (keep = Resp Gp) ;
set tmpXYA end=Last;
array Rsp(39,2) ;
retain Rsp;
Rsp(_N_,1) = X;
Rsp(_N_,2) = Y;
if Last then do;
do i=1 to 39;
Resp = Rsp(i,1); Gp = "X";
Output; end;
do i=1 to 39;
Resp = Rsp(i,2); Gp = "Y";
Output; end;
end; run;
ALTERNATIVE METHODS FOR CONVERTING tmpRsp TO tmpXY:
(iii)
data tmpXYB (keep = X Y);
set tmpRspC end=Last;
array Rsp(39,2) ;
retain Rsp;
retain Xctr Yctr;
if _N_=1 then do; Xctr=0; Yctr=0; end;
if Gp = "X" then do;
Xctr=Xctr+1; Rsp(Xctr,1) = Resp;
end; else do;
Yctr=Yctr+1; Rsp(Yctr,2) = Resp;
end;
if Last then do i=1 to 39;
X = Rsp(i,1); Y = Rsp(i,2);
Output; end; run;
(iv)
data tmpX (keep=X) tmpY (keep=Y);
set tmpRspC;
if Gp="X" then do;
X=Resp; output tmpX; end;
else do; Y=Resp; output tmpY; end;
data tmpXYC ;
merge tmpX tmpY; run;