Table of Contents
A Two Proportion Z-Test is a statistical method used to compare the proportions of two independent populations. This test can be performed in SAS by using the PROC PROB procedure. First, the data must be organized in a table format with the two populations listed in separate columns. Then, the PROC PROB statement should be followed by the TEST statement, specifying the two populations to be compared. The output will include the test statistic, confidence interval, and p-value, which can be used to determine the significance of the difference between the two proportions. Additionally, SAS provides options for adjusting for continuity correction and specifying the alternative hypothesis. This allows for a comprehensive and accurate analysis of the two proportions using SAS.
Perform a Two Proportion Z-Test in SAS
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:
- 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): π1 > π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 n2 are 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 printdata=my_data;

/*perform two proportion z-test*/
proc freqdata=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:
- 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:
Cite this article
stats writer (2024). How can a Two Proportion Z-Test be performed in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-a-two-proportion-z-test-be-performed-in-sas/
stats writer. "How can a Two Proportion Z-Test be performed in SAS?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-a-two-proportion-z-test-be-performed-in-sas/.
stats writer. "How can a Two Proportion Z-Test be performed in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-a-two-proportion-z-test-be-performed-in-sas/.
stats writer (2024) 'How can a Two Proportion Z-Test be performed in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-a-two-proportion-z-test-be-performed-in-sas/.
[1] stats writer, "How can a Two Proportion Z-Test be performed in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can a Two Proportion Z-Test be performed in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
