T-test in SAS datastep

The following SAS datastep conducts a test using functions in a datastep.

proc means data=both STACKODSOUTPUT n mean std min max stderr ;
class treat ;
var

<Variables here>

;
ods output summary=kaz2;
run;

data c;set kaz2;
if treat=0;
N_c=N;
mean_c=mean;
StdDev_c=StdDev;
Min_C=Min;
Max_C=Max;
StdErr_C=StdErr;
keep N_C MEAN_C StdDev_c MIN_C MAX_C StdErr_C Variable label;
run;

data t;set kaz2;
if treat=1;
N_t=N;
mean_t=mean;
StdDev_t=StdDev;
Min_t=Min;
Max_t=Max;
StdErr_t=StdErr;
Variable_QC=Variable;
keep N_T MEAN_T StdDev_t MIN_T MAX_T Variable_QC StdErr_t;
run;

data merge_CT;
merge C T ;
difference=MEAN_T-MEAN_C;

/*https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm*/
POOLED_SE=sqrt( ( (StdDev_t*StdDev_t) / N_T ) + ( (StdDev_c*StdDev_c ) / N_C ) );

T_value=abs(difference)/POOLED_SE;

P_value=(1-probnorm(T_value))*2;
*if P_value < 0.1 then sig="t";
if P_value < 0.05 then sig="* ";
if P_value < 0.01 then sig="** ";
if P_value < 0.001 then sig="***";
if P_value =. then sig="";

run;

Leave a Reply