The one sample t test is used to compare the mean of a sample to some specific value. You set up a null hypothesis H_0: \mu=\mu_0 and test it against the alternative hypothesis. The alternative hypothesis can vary, based on whether you are performing a one sided or two sided t test. This post demonstrates how to perform simple one sample t tests in SAS.

Two Sided t Test Example

In the two sided t test case, we test the null hypothesis H_0 against the alternative hypotheses H_1: \mu \ne \mu_0. This means that we are not making any assumptions on whether we suspect that the population mean is less than or greater than the hypothesized mean \mu_0. We only suspect that it is different. First, we assume that the sample comes from a normal distribution. If you want to assess the normality of your data, check out my blog post Fit Continuous Distribution in SAS. Next, we calculate the t statistic as

(1)   \begin{equation*} t = \frac{\bar{x} - \mu_0}{SD / \sqrt{n}}. \end{equation*}

The t statistic measures how many standard errors the sample mean \bar{x} is from the hypothesized mean \mu_0. That means that the t statistic expresses how much the sample mean deviates from the true value, expressed in relation to the uncertainty of the mean.

Next, we evaluate the t statistic in both tales of a T Distribution with n-1 degrees of freedom (your sample size) and calculate the p value as the area under the curve in the tails more extreme than our t statistic.

We use PROC TTEST in SAS to assess the null hypotheses H_0: \mu = 60 in the sashelp.class data set to test whether we can assume that the average height of the students can be assumed to be 60.

proc ttest data=sashelp.class h0=60; sides=2 alpha=0.05;
   var height;
run;
Two Sided t Test distribution

To the right you can see the relevant t distribution for the two sided t test. The red area in the tails under the curve represent the p-value of 0.0624. This means that we reject the null hypothesis H_0: \mu=60. This leds us to accept the alternative hypothesis H_1: \mu \ne 60.

One Sided t Test Example
In the previous example we tested the null hypothesis H_0: \mu=\mu_0 against the alternative hypothesis H_1: \mu \ne \mu_0. This is called the two sided t test because you can not say anything about the direction of the alternative hypothesis.

However, if you suspect that if your null hypothesis does not hold, then the average height of students is either larger or smaller than your hypothesized mean, then you perform a one sided t test. You can do this in PROC TTEST as follows.

proc ttest data=sashelp.class h0=60 sides=u alpha=0.05;
   where sex='M';
   var height;
run;
One Sided t Test distribution

The only difference between the twp PROC TTEST steps is that we specify the SIDES=U in the latter step. This means that now, we test the null hypothesis H_0: \mu = 60 against the alternative hypothesis H_1: \mu > 60. You can see the relevant t distribution along with the t statistic and p value to the right.

Summary

You can use the one sample t test to assess whether the population mean is equal to some specified mean using the PROC TTEST. This is the easiest and most obvious way, but there are other procedures, that will yield the exact same result.

For a more thorough introduction to the one sample t test, watch the youtube video Introduction To The One Sample T Test by JbStatistics.

Finally, you can download the entire program from this post here. The code that produces the graphs are included.