How to perform a Two Proportion Z-Test in SAS?

A two proportion Z-Test in SAS is a statistical inference test that can be used to compare the proportions of two population samples. It is performed by using the PROC FREQ procedure in SAS, specifying the TABLES statement and the CHISQ option, which will enable the Z-Test calculation. The output will include statistics such as the test value, the p-value, and confidence intervals for the proportions being compared.


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:

  • H0: μ1 = μ2 (the two population proportions are equal)

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

  • H1 (two-tailed): π1 ≠ π2 (the two population proportions are not equal)
  • H1 (left-tailed): π1 < π2 (population 1 proportion is less than population 2 proportion)
  • H1 (right-tailed): π> π2 (population 1 proportion is greater than population 2 proportion)

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

z = (p1-p2) / √p(1-p)(1/n1+1/n2)

where p1 and p2 are the sample proportions, n1 and nare the sample sizes, and where p is the total pooled proportion calculated as:

p = (p1n1 + p2n2)/(n1+n2)

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;

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

two proportion z-test in SAS

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:

  • H0π1 = π2  (the two population proportions are equal)
  • H1π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.

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

x