Table of Contents
The ability to compare statistical inference test is a fundamental requirement in data analysis across fields like medicine, social sciences, and market research. A critical tool for this purpose is the Two Proportion Z-Test, designed specifically to evaluate whether a significant difference exists between the proportions observed in two distinct population samples. When working within the analytical environment of SAS, this powerful comparison is efficiently executed using the familiar PROC FREQ procedure. By strategically utilizing the TABLES statement coupled with the necessary options, SAS calculates the required statistics, yielding crucial output such as the Z-test statistic, the associated p-value, and confidence intervals for the observed proportions. This procedure transforms raw categorical data into actionable insights regarding population characteristics.
Understanding the Two Proportion Z-Test
The core purpose of a Two Proportion Z-Test is to determine if an observed difference between two sample proportions is large enough to conclude that the underlying true population proportions are statistically distinct. This test is employed when the response variable is categorical, often binary (success/failure, yes/no), and we are comparing the rates of “success” across two independent groups. Unlike tests comparing means, the Z-Test specifically focuses on rates and frequencies, making it indispensable for analyses concerning market penetration rates, disease prevalence, or public opinion differences between demographics.
Before execution, it is paramount to establish the formalized hypotheses that drive the statistical decision-making process. These hypotheses frame the question being asked and define the potential outcomes. By formalizing the expectations using a statistical framework, we ensure that the conclusions drawn are based on rigorous, quantifiable evidence rather than mere speculation. This structured approach allows researchers to maintain objectivity throughout the analysis.
Theoretical Foundation and Hypotheses
The foundation of this test rests upon the Null Hypothesis (H0), which posits that there is no difference between the true proportions of the two populations being analyzed. This serves as the baseline assumption that the statistical evidence must overcome to prove otherwise. The alternative hypotheses (H1) represent the different ways in which a difference might manifest, allowing for specific directional or non-directional tests based on the researcher’s initial question or expectation.
The fundamental structure of the Null Hypothesis for the two proportion Z-Test is defined as follows, assuming that π1 and π2 represent the true population proportions:
- H0: π1 = π2 (The two population proportions are equal, meaning the difference is zero.)
The corresponding Alternative Hypothesis (H1) dictates the nature of the test, which can be two-tailed, left-tailed, or right-tailed, reflecting different research questions regarding the relationship between the two proportions:
- H1 (Two-Tailed Test): π1 ≠ π2 (The two population proportions are significantly different, regardless of direction. This is the most common default test.)
- H1 (Left-Tailed Test): π1 < π2 (The proportion of Population 1 is hypothesized to be strictly less than the proportion of Population 2.)
- H1 (Right-Tailed Test): π1 > π2 (The proportion of Population 1 is hypothesized to be strictly greater than the proportion of Population 2.)
To calculate the necessary test statistic (z), which quantifies how many standard deviations the observed difference in sample proportions is from the hypothesized difference (usually zero), a specific formula rooted in the principles of sampling distribution theory is utilized. This formula incorporates the sample proportions and the pooled proportion, which provides a better estimate of the common proportion under the assumption that the null hypothesis is true.
The formula used to calculate the z test statistic is:
z = (p1-p2) / √p(1-p)(1/n1+1/n2)
In this formula, p1 and p2 represent the observed sample proportions for the two groups, while n1 and n2 denote the respective sample sizes. The term p stands for the total pooled sample proportion, which is crucial for estimating the standard error under H0. The pooled proportion calculation ensures that both sample sizes contribute proportionally to the overall variability estimate, thus improving the reliability of the Z-score calculation.
The calculation for the pooled proportion p is given by:
p = (p1n1 + p2n2)/(n1+n2)
Once the Z-statistic is calculated, it is compared against the critical Z-value derived from the standard normal distribution, or more commonly, converted into a p-value. If the resulting p-value is lower than the predefined significance level (alpha, typically 0.05), the evidence suggests that the observed difference is unlikely to have occurred by random chance alone, leading to the rejection of the Null Hypothesis.
Prerequisites and Assumptions for the Z-Test
While the Two Proportion Z-Test is robust, its validity depends on several key assumptions being met. Failure to meet these prerequisites can lead to inaccurate p-values and unreliable conclusions. Primarily, the samples must be drawn randomly and independently from their respective populations. Independence ensures that the outcome in one sample group does not influence the outcome in the other, which is crucial for calculating the combined standard error.
Furthermore, the sampling distribution of the difference in proportions must be approximately normal. This is achieved through the satisfaction of the large sample size condition, often referred to as the Central Limit Theorem criteria for proportions. A common rule of thumb is that there must be at least 10 “successes” and 10 “failures” (or alternatively, 5 successes and 5 failures) in each of the two samples. When these counts are sufficiently large, the normal approximation for the binomial distribution is considered appropriate, justifying the use of the Z-statistic.
Finally, the data used must be count data summarized into categorical variables. SAS handles this through the `WEIGHT` statement within PROC FREQ, where the variable designated as the count represents the frequency of observations in each category defined by the classification variables. Understanding how to structure the input data correctly is the first step toward successful execution of the test in SAS.
Setting Up the Data in SAS
To demonstrate the practical application of the two proportion Z-test, consider a scenario where a researcher wants to compare public support for a specific piece of legislation across two distinct geographical areas, County A and County B. A random sample of residents is surveyed in each county, and their response (Support or Reject) is recorded. In this example, 50 residents were sampled from each county, yielding categorical results suitable for proportional testing.
The critical step in SAS is creating a structured dataset that summarizes these counts, making them compatible with the PROC FREQ procedure. We need variables defining the groups (County), the outcome categories (Status), and the raw counts for each combination (Count). The following SAS code block efficiently creates and displays this summarized dataset, which is the necessary input for the hypothesis test:
/*create dataset for two proportion comparison*/ data my_data; input county $ status $ count; datalines; A Support 34 A Reject 16 B Support 29 B Reject 21 ; run; /*view dataset to ensure data integrity*/ proc print data=my_data;
This dataset structure clearly indicates that in County A, 34 residents support the law and 16 reject it, totaling 50. Similarly, in County B, 29 support and 21 reject the law, also totaling 50. This compact contingency table format is optimized for categorical analysis procedures in SAS.

Executing the Two Proportion Z-Test using PROC FREQ
The standard procedure for conducting the Two Proportion Z-Test in SAS involves using PROC FREQ, which is primarily designed for generating frequency tables and contingency analyses. While often associated with Chi-Square tests, PROC FREQ offers specialized options within the TABLES statement to calculate measures of association and tests specific to proportional differences, including the Z-Test itself.
To explicitly request the two-sample proportion test, we must use the RISKDIFF option. This option calculates the difference between column proportions (or row proportions, depending on the variable order) and provides the associated test of equality, including the Z-statistic and its corresponding p-value. Crucially, we must also specify the WEIGHT statement to instruct SAS that the variable `count` contains the frequencies, rather than treating each line as a single observation.
The required syntax below directs SAS to perform the proportion comparison. The `county * status` specification creates a two-way contingency table, where `county` is the grouping variable and `status` is the outcome variable. The `RISKDIFF(EQUAL VAR = NULL)` option is essential: RISKDIFF initiates the calculation of risk differences (proportion differences), and EQUAL VAR = NULL instructs the procedure to calculate the standard error based on the pooled proportion under the assumption of the Null Hypothesis (i.e., assuming equal variances).
/*perform two proportion z-test using PROC FREQ*/
proc freq data=my_data;
weight count;
tables county * status / riskdiff(equal var = null);
run;Running this code generates extensive output, but the key statistics relevant to the Two Proportion Z-Test are consolidated within the section titled “Risk Difference Test.”

Interpreting the SAS Output: The Risk Difference Test
The output generated by PROC FREQ contains several tables, including the standard contingency table and various association statistics. For the specific two proportion Z-Test, the researcher must focus specifically on the table labeled Risk Difference Test. This table presents the calculated difference in proportions, the standard error of that difference (under H0), the Z-test statistic, and the associated two-sided p-value.
Based on the provided output image, we extract the critical results necessary for making a statistical decision:
- Z-Test Statistic: -1.0356
- Two-Sided P-Value: 0.3004
The Z-test statistic of -1.0356 indicates that the difference between the sample proportions (pA – pB) is approximately 1.04 standard errors below zero. The sign of the statistic simply reflects the order of subtraction (County A proportion minus County B proportion). The magnitude of this statistic, however, is not large enough to fall into the extreme tails of the standard normal distribution, suggesting a non-significant result.
Drawing Conclusions from the P-Value
Recall that this particular two proportion Z-test was executed with the intention of performing a non-directional, two-tailed test, utilizing the following formal hypotheses:
- H0: π1 = π2 (The proportion of support is the same in both counties.)
- H1: π1 ≠ π2 (The proportion of support is different between the two counties.)
To reach a definitive conclusion, the calculated p-value must be compared against the predetermined significance level (α). Assuming a standard significance level of α = 0.05, we apply the decision rule: If p-value ≤ α, reject H0; otherwise, fail to reject H0.
In this specific example, the observed p-value is 0.3004. Since 0.3004 is substantially greater than 0.05, we must fail to reject the Null Hypothesis. This critical failure to reject signifies that there is insufficient statistical evidence, based on the collected sample data, to conclusively state that the true proportion of residents supporting the law is different between County A and County B. Any observed difference in the samples is likely attributable to random sampling variability rather than a genuine population difference.
Advanced Considerations and Alternatives
While PROC FREQ combined with the RISKDIFF(EQUAL VAR = NULL) option is the standard method for running the pooled two proportion Z-Test in SAS, analysts should be aware of alternative approaches and procedures. For instance, the PROC LOGISTIC procedure can also be used to perform proportional tests, especially when control for confounding variables is necessary, offering a more generalized linear model approach to the binary outcome data.
Furthermore, when the sample sizes are small and the assumption of normality is violated (i.e., fewer than 5 or 10 successes/failures in a group), the traditional Z-Test becomes less reliable. In such cases, analysts might rely on non-parametric alternatives, such as Fisher’s Exact Test (also available through PROC FREQ using the FISHER option), or utilize score confidence intervals or exact tests which do not rely on the normal approximation. These alternative methods ensure statistical validity even under restrictive data conditions.
The following tutorials explain how to perform other common statistical tests in SAS:
Cite this article
stats writer (2025). How to perform a Two Proportion Z-Test in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-to-perform-a-two-proportion-z-test-in-sas/
stats writer. "How to perform a Two Proportion Z-Test in SAS?." PSYCHOLOGICAL SCALES, 19 Nov. 2025, https://scales.arabpsychology.com/stats/how-to-perform-a-two-proportion-z-test-in-sas/.
stats writer. "How to perform a Two Proportion Z-Test in SAS?." PSYCHOLOGICAL SCALES, 2025. https://scales.arabpsychology.com/stats/how-to-perform-a-two-proportion-z-test-in-sas/.
stats writer (2025) 'How to perform a Two Proportion Z-Test in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-to-perform-a-two-proportion-z-test-in-sas/.
[1] stats writer, "How to perform a Two Proportion Z-Test in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, November, 2025.
stats writer. How to perform a Two Proportion Z-Test in SAS?. PSYCHOLOGICAL SCALES. 2025;vol(issue):pages.