FREQTAB Procedure
Getting Started: FREQTAB Procedure
(View the complete code for this example.)
This example shows you how to use the FREQTAB procedure to construct crosstabulation tables and produce chi-square statistics and measures of association.
The data table mylib.School_Survey consists of hypothetical data that are based on a customer satisfaction survey for a school information system. This data table includes the following variables for the survey respondents: ID (respondent identification), Response, SchoolType, and State. Figure 1 displays the first 20 observations of the data table.
Figure 1: School_Survey Data Table (First 20 Observations)
| Obs | ID | Response | SchoolType | State |
|---|---|---|---|---|
| 1 | 26629 | Satisfied | Middle School (Public) | TN |
| 2 | 25834 | Neutral | High School (Public) | TN |
| 3 | 14821 | Very Satisfied | High School (Private) | NC |
| 4 | 4153 | Neutral | Middle School (Private) | GA |
| 5 | 6185 | Very Satisfied | High School (Private) | GA |
| 6 | 6164 | Unsatisfied | High School (Public) | GA |
| 7 | 6386 | Neutral | Middle School (Public) | GA |
| 8 | 1011 | Neutral | High School (Private) | GA |
| 9 | 28916 | Very Satisfied | High School (Private) | TN |
| 10 | 10601 | Neutral | High School (Public) | NC |
| 11 | 17900 | Satisfied | High School (Private) | NC |
| 12 | 2935 | Unsatisfied | High School (Private) | GA |
| 13 | 9799 | Unsatisfied | High School (Private) | NC |
| 14 | 23754 | Very Satisfied | Middle School (Public) | TN |
| 15 | 9516 | Neutral | Middle School (Public) | NC |
| 16 | 4614 | Very Unsatisfied | Middle School (Private) | GA |
| 17 | 12443 | Unsatisfied | Middle School (Public) | NC |
| 18 | 5356 | Very Satisfied | High School (Public) | GA |
| 19 | 15189 | Unsatisfied | High School (Private) | NC |
| 20 | 3309 | Satisfied | High School (Public) | GA |
Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.
The following PROC FREQTAB statements request a two-way crosstabulation of SchoolType and Response. These statements assume that your libref is named mylib, but you can substitute any appropriately defined libref.
proc freqtab data=mylib.School_Survey;
tables SchoolType * Response /
crosslist chisq measures(cl);
run;
The PROC FREQTAB statement invokes the procedure and identifies the data table to be analyzed. The TABLES statement requests a two-way crosstabulation of SchoolType and Response. The table request syntax in PROC FREQTAB is identical to the table request syntax in the FREQ procedure. You can specify one-way, two-way, and multiway table requests. You can specify more than one table request in the same TABLES statement, and you can specify multiple TABLES statements in the same invocation of the procedure.
The CROSSLIST option displays the crosstabulation table in column format; by default, PROC FREQTAB displays crosstabulation tables in table cell format. The CHISQ option requests chi-square tests, and the MEASURES option requests measures of association for this two-way crosstabulation table. The MEASURES(CL) option requests confidence limits for the measures of association.
Figure 2 shows the crosstabulation table of SchoolType by Response. You can customize the contents of this table by specifying options in the TABLES statement. For example, the NOCOL option suppresses the column percentages, the EXPECTED option displays the expected cell frequencies (under independence), and the STDRES option displays the standardized residuals.
Figure 2: Crosstabulation Table
| Table of SchoolType by Response | |||||
|---|---|---|---|---|---|
| SchoolType | Response | Frequency | Percent | Row Percent | Column Percent |
| Middle School (Private) | Very Satisfied | 594 | 1.83 | 15.77 | 12.05 |
| Satisfied | 823 | 2.54 | 21.85 | 11.32 | |
| Neutral | 1183 | 3.64 | 31.41 | 12.51 | |
| Unsatisfied | 846 | 2.61 | 22.46 | 11.16 | |
| Very Unsatisfied | 320 | 0.99 | 8.50 | 9.93 | |
| Total | 3766 | 11.60 | 100.00 | ||
| Middle School (Public) | Very Satisfied | 1261 | 3.88 | 13.94 | 25.58 |
| Satisfied | 1811 | 5.58 | 20.02 | 24.91 | |
| Neutral | 2494 | 7.68 | 27.56 | 26.37 | |
| Unsatisfied | 2364 | 7.28 | 26.13 | 31.18 | |
| Very Unsatisfied | 1118 | 3.44 | 12.36 | 34.70 | |
| Total | 9048 | 27.88 | 100.00 | ||
| High School (Private) | Very Satisfied | 1459 | 4.49 | 18.23 | 29.60 |
| Satisfied | 2160 | 6.65 | 26.99 | 29.72 | |
| Neutral | 2422 | 7.46 | 30.26 | 25.61 | |
| Unsatisfied | 1363 | 4.20 | 17.03 | 17.98 | |
| Very Unsatisfied | 599 | 1.85 | 7.48 | 18.59 | |
| Total | 8003 | 24.66 | 100.00 | ||
| High School (Public) | Very Satisfied | 1615 | 4.98 | 13.87 | 32.77 |
| Satisfied | 2475 | 7.63 | 21.26 | 34.05 | |
| Neutral | 3359 | 10.35 | 28.85 | 35.51 | |
| Unsatisfied | 3008 | 9.27 | 25.84 | 39.68 | |
| Very Unsatisfied | 1185 | 3.65 | 10.18 | 36.78 | |
| Total | 11642 | 35.87 | 100.00 | ||
| Total | Very Satisfied | 4929 | 15.19 | 100.00 | |
| Satisfied | 7269 | 22.39 | 100.00 | ||
| Neutral | 9458 | 29.14 | 100.00 | ||
| Unsatisfied | 7581 | 23.36 | 100.00 | ||
| Very Unsatisfied | 3222 | 9.93 | 100.00 | ||
| Total | 32459 | 100.00 | |||
Figure 3 shows the chi-square statistics, and Figure 4 shows the measures of association for the table of SchoolType and Response.
Figure 3: Chi-Square Statistics
| Statistics for Table of SchoolType by Response |
| Statistic | DF | Value | Prob |
|---|---|---|---|
| Chi-Square | 12 | 505.1446 | <.0001 |
| Likelihood Ratio Chi-Square | 12 | 512.2769 | <.0001 |
| Mantel-Haenszel Chi-Square | 1 | 0.0050 | 0.9438 |
| Phi Coefficient | 0.1247 | ||
| Contingency Coefficient | 0.1238 | ||
| Cramer's V | 0.0720 |
Figure 4: Measures of Association
| Statistic | Value | ASE | 95% Confidence Limits | |
|---|---|---|---|---|
| Gamma | 0.0024 | 0.0061 | -0.0097 | 0.0144 |
| Kendall's Tau-b | 0.0018 | 0.0046 | -0.0073 | 0.0108 |
| Stuart's Tau-c | 0.0018 | 0.0046 | -0.0072 | 0.0108 |
| Somers' D C|R | 0.0018 | 0.0048 | -0.0075 | 0.0112 |
| Somers' D R|C | 0.0017 | 0.0044 | -0.0070 | 0.0104 |
| Pearson Correlation | -0.0004 | 0.0055 | -0.0112 | 0.0104 |
| Spearman Correlation | 0.0018 | 0.0056 | -0.0090 | 0.0127 |
| Lambda Asymmetric C|R | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
| Lambda Asymmetric R|C | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
| Lambda Symmetric | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
| Uncertainty Coefficient C|R | 0.0051 | 0.0004 | 0.0042 | 0.0060 |
| Uncertainty Coefficient R|C | 0.0060 | 0.0005 | 0.0050 | 0.0070 |
| Uncertainty Coefficient Symmetric | 0.0055 | 0.0005 | 0.0046 | 0.0064 |
| Sample Size = 32459 |
PROC FREQTAB can produce plots as part of its output by using ODS Graphics. The following statements show how to produce a frequency plot and a mosaic plot for a two-way crosstabulation table. The ODS GRAPHICS ON statement enables ODS Graphics, which is required in order to produce plots.
The PLOTS=FREQPLOT option in the TABLES statement requests a frequency plot of the two-way table of Response by SchoolType. The TWOWAY=CLUSTER plot-option requests a cluster grouped bar chart. The ORIENT=H plot-option specifies horizontal orientation, which places the variable levels on the Y-axis and the percentages on the X-axis. The SCALE=GROUPPERCENT plot-option requests a plot of group (column) percentages (instead of frequencies).
The PLOTS=MOSAICPLOT option requests a mosaic plot of Response by SchoolType. The COLORSTAT=STDRES plot-option colors the mosaic plot tiles according to the standardized residuals of the corresponding table cells.
ods graphics on;
proc freqtab data=mylib.School_Survey;
tables Response * SchoolType /
plots=(freqplot(twoway=cluster orient=h scale=grouppercent)
mosaicplot(colorstat=stdres));
run;
ods graphics off;
Figure 5 displays the two-way frequency plot of SchoolType and Response. Figure 6 displays the mosaic plot of this crosstabulation.
Figure 5: Frequency Plot (Grouped Bar Chart)

Figure 6: Mosaic Plot

The following PROC FREQTAB statements produce a multiway table of State by SchoolType by Response. The TABLES statement requests the multiway table in which SchoolType is the row variable, Response is the column variable, and State is the stratum variable. This request produces a separate two-way table of SchoolType by Response for each level (stratum) of the variable State. The CMH option in the TABLES statement requests stratified analysis, which adjusts for the effect of State.
proc freqtab data=mylib.School_Survey;
tables State * SchoolType * Response / cmh;
run;
Figure 7 displays the two-way table of SchoolType and Response for State = 'GA'. PROC FREQTAB also produces two-way tables for the other states, but these results are not displayed here. Figure 8 displays the CMH summary statistics.
Figure 7: Two-Way Table for State=GA
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Figure 8: CMH Test of No Association
| Summary Statistics for SchoolType by Response Controlling for State |
| Cochran-Mantel-Haenszel Statistics (Based on Table Scores) | ||||
|---|---|---|---|---|
| Statistic | Alternative Hypothesis | DF | Value | Prob |
| 1 | Nonzero Correlation | 1 | 0.0086 | 0.9262 |
| 2 | Row Mean Scores Differ | 3 | 406.7786 | <.0001 |
| 3 | General Association | 12 | 508.7656 | <.0001 |
| Total Sample Size = 32459 |