A **two proportion z-test** is used to determine if there is a statistically significant difference between two population proportions.

This test uses the following null hypothesis:

**H**μ_{0}:_{1}= μ_{2}(the two population proportions are equal)

The alternative hypothesis can be either two-tailed, left-tailed, or right-tailed:

**H**π_{1}(two-tailed):≠ π_{1}_{2}(the two population proportions are not equal)**H**π_{1}(left-tailed):_{1}< π_{2}(population 1 proportion is less than population 2 proportion)**H**π_{1}(right-tailed):> π_{1 }_{2}(population 1 proportion is greater than population 2 proportion)

We use the following formula to calculate the test statistic z:

**z **= (p_{1}-p_{2}) / √p(1-p)(1/n_{1}+1/n_{2})

where p_{1} and p_{2} are the sample proportions, n_{1 }and n_{2 }are the sample sizes, and where p is the total pooled proportion calculated as:

p = (p_{1}n_{1} + p_{2}n_{2})/(n_{1}+n_{2})

If the p-value that corresponds to the test statistic z is less than your chosen significance level (common choices are 0.10, 0.05, and 0.01) then you can reject the null hypothesis.

The following example shows how to perform a two proportion z-test in SAS.

**Example: Two Proportion Z-Test in SAS**

Suppose we want to know if there is a difference in the proportion of residents who support a certain law in county A compared to the proportion who support the law in county B.

To test this, we collect a random sample of 50 residents from each county and count how many support the law.

The following code shows how to create a dataset that summarizes the number of residents that support the law from each county:

/*create dataset*/ data my_data; input county $ status $ count; datalines; A Support 34 A Reject 16 B Support 29 B Reject 21 ; run; /*view dataset*/ proc print data=my_data;

We can then use the **PROC FREQ** statement with the option **riskdiff(equal var = null)** to perform the two proportion z-test:

**/*perform two proportion z-test*/
proc freq data=my_data;
weight count;
tables county * status / riskdiff(equal var = null);
run;**

From the **Risk Difference Test** table in the output we can see the following information:

- z-test statistic:
**-1.0356** - two-sided p-value:
**0.3004**

This particular two proportion z-test used the following hypotheses:

**H**π_{0}:= π_{1}_{2}(the two population proportions are equal)**H**π_{1}:≠ π_{1}_{2}(the two population proportions are not equal)

Since the p-value in the output is not less than 0.05, we fail to reject the null hypothesis.

This means we do not have sufficient evidence to say that the proportion of residents who support this law is different between the two counties.

**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