Welch’s t-test is used to compare the means between two independent groups when it is not assumed that the two groups have equal variances.
This tutorial explains how to perform a Welch’s t-test in SAS.
Example: Welch’s t-Test in SAS
Suppose a teacher wants to compare the exam scores of 12 students who used an exam prep booklet to prepare for some exam vs. 12 students who did not.
The following lists show the exam scores for the students in each group:
Booklet: 90, 85, 88, 89, 94, 91, 79, 83, 87, 88, 91, 90
No Booklet: 67, 90, 71, 95, 88, 83, 72, 66, 75, 86, 93, 84
Use the following steps to perform Welch’s t-test to determine if the mean exam score is equal between the two groups.
Step 1: Create the data.
First, we’ll use the following code to create the dataset in SAS:
/*create dataset*/ data exam_scores; input group $ score; datalines; booklet 90 booklet 85 booklet 88 booklet 89 booklet 94 booklet 91 booklet 79 booklet 83 booklet 87 booklet 88 booklet 91 booklet 90 no_booklet 67 no_booklet 90 no_booklet 71 no_booklet 95 no_booklet 88 no_booklet 83 no_booklet 72 no_booklet 66 no_booklet 75 no_booklet 86 no_booklet 93 no_booklet 84 ; run;
Step 2: Perform Welch’s t-test.
Next, we’ll use proc ttest to perform Welch’s t-test:
/*perform Welch's t-test*/ proc ttest data=exam_scores alpha=0.05; class group; var score; run;
The last table titled Equality of Variances performs an F-test to determine if the variances are equal between the two samples.
This F-test uses the following null and alternative hypotheses:
- H0: The variances are equal.
- HA: The variances are not equal.
Since the p-value (.0046) of this test is less than .05, we reject the null hypothesis. This means the two sample variances are not equal.
Thus, we must refer to the row titled Unequal in the second to last table to determine the t value and corresponding p-value to use:
- t Value: 2.24
- p-value: .0417
Recall that Welch’s t-test uses the following null and alternative hypotheses:
- H0: μ1 = μ2
- HA: μ1 ≠ μ2
Since the p-value (.0417) is less than .05, we reject the null hypothesis.
This means we have sufficient evidence to say that the mean exam score between the two groups is not equal.
Bonus: Feel free to use this Welch’s t-test Calculator to automatically perform Welch’s t-test for any two samples.
Additional Resources
The following tutorials explain how to perform other common statistical tests in SAS:
How to Perform a One Sample t-Test in SAS
How to Perform a Two Sample t-Test in SAS
How to Perform a Paired Samples t-Test in SAS