How to perform a Paired Samples t-Test in SAS

A Paired Samples t-Test in SAS is a statistical test that can be used to compare the means of two related variables. To perform the test in SAS, you will need to use the PROC TTEST statement along with the PAIRED and VAR statements to specify the two variables that you would like to compare. You may also use the MEANS statement to get descriptive statistics for the two variables. After running the code, a table will be printed that contains the t-statistic, degrees of freedom, and the p-value associated with the test.

A is used to compare the means of two samples when each in one sample can be paired with an observation in the other sample.

This tutorial explains how to perform a paired samples t-test in SAS.

Example: Paired Samples t-Test in SAS

Suppose a professor wants to determine if a certain study program affects test scores. To test this, he 15 students to take a pre-test. Then, he has each student use the study program for one month and then a post-test of similar difficulty.

The test scores for each of the 15 students are shown below:

To compare the difference between the mean scores on the pre-test and post-test, the professor can use a paired samples t-test because for each student their pre-test score can be paired with their post-test score.

Use the following steps to perform this paired samples t-test in SAS:

Step 1: Create the Data

First, let’s use the following code to create the dataset in SAS:

/*create dataset*/
data test_scores;
    input pre post;
88 91
82 84
84 88
93 90
75 79
78 80
84 88
87 90
95 90
91 96
83 88
89 89
77 81
68 74
91 92

/*view dataset*/
proc print data=test_scores;

Step 2: Perform the Paired Samples t-test

Next, we can use proc ttest to perform the paired samples t-test:

/*perform paired samples t-test*/
proc ttest data=test_scores alpha=.05;
    paired pre*post;

paired samples t-test in SAS

From the output we can see the following:

  • Mean difference between pre-test and post-test score: -2.3333
  • 95% Confidence Interval for Mean difference: [-4.0165, -.6502]

We can also see the t test statistic and corresponding two-sided p-value:

  • t test statistic: -2.97
  • p-value: .0101

In this example, the paired samples t-test uses the following null and alternative :

  • H0The mean pre-test and post-test scores are equal
  • HA: The mean pre-test and post-test scores are not equal

Since the p-value (0.0101) is less than 0.05, we reject the null hypothesis.

This means we have sufficient evidence to say that the true mean test score is different for students before and after participating in the study program.

The following tutorials explain how to perform other common statistical tests in SAS: