How to Perform a Mann-Whitney U Test in SAS


A Mann-Whitney U test (sometimes called the Wilcoxon rank-sum test) is used to compare the differences between two samples when the sample distributions are not normally distributed and the sample sizes are small (n <30).

It is considered to be the nonparametric equivalent to the two sample t-test.

This tutorial explains how to perform a Mann-Whitney U test in SAS.

Example: Mann-Whitney U Test in SAS

Suppose researchers want to know if a fuel treatment leads to a change in the average mpg of a car. To test this, they conduct an experiment in which they measure the mpg of 12 cars with the fuel treatment and 12 cars without it.

The results are shown below:

Because the sample sizes are small and they suspect that the sample distributions are not normally distributed, they decide to perform a Mann-Whitney U test to determine if there is a statistically significant difference in mpg between the two groups.

Use the following steps to perform a Mann-Whitney U test in SAS.

Step 1: Create the Dataset

First, we’ll use the following code to create the dataset in SAS:

/*create dataset*/
data mpg_data;
    input group $ mpg;
    datalines;
treated 24
treated 25
treated 21
treated 22
treated 23
treated 18
treated 17
treated 28
treated 24
treated 27
treated 21
treated 23
untreated 20
untreated 23
untreated 21
untreated 25
untreated 18
untreated 17
untreated 18
untreated 24
untreated 20
untreated 24
untreated 23
untreated 19
;
run;

Step 2: Perform the Mann Whitney U Test

Next, we’ll use proc npar1way to perform the Mann Whitney U test:

/*perform Mann Whitney U test*/
proc npar1way data=mpg_data wilcoxon;
    class group;
    var mpg;
run;

From the Wilcoxon Two-Sample Test table, we see that the two-sided p-value of the test turns out to be 0.2114.

Recall that the Mann Whitney U test uses the following null and alternative hypotheses:

  • H0: The two populations have the same median.
  • HA: The two populations have different medians.

Since the p-value of the test (.2114) is not less than .05, we fail to reject the null hypothesis.

This means we do not have sufficient evidence to say that the mpg is different between the cars that receive fuel treatment and those that don’t.

SAS also provides boxplots to visualize the distribution of mpg values for each group:

From the plot we can see the cars that received the fuel treatment tended to have higher mpg values, but from the results of the Mann Whitney U test we know that the differences between the two groups was not statistically significant.

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
How to Perform a Wilcoxon Signed Rank Test in SAS

Leave a Reply

Your email address will not be published.