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)

ObsIDResponseSchoolTypeState
126629SatisfiedMiddle School (Public)TN
225834NeutralHigh School (Public)TN
314821Very SatisfiedHigh School (Private)NC
44153NeutralMiddle School (Private)GA
56185Very SatisfiedHigh School (Private)GA
66164UnsatisfiedHigh School (Public)GA
76386NeutralMiddle School (Public)GA
81011NeutralHigh School (Private)GA
928916Very SatisfiedHigh School (Private)TN
1010601NeutralHigh School (Public)NC
1117900SatisfiedHigh School (Private)NC
122935UnsatisfiedHigh School (Private)GA
139799UnsatisfiedHigh School (Private)NC
1423754Very SatisfiedMiddle School (Public)TN
159516NeutralMiddle School (Public)NC
164614Very UnsatisfiedMiddle School (Private)GA
1712443UnsatisfiedMiddle School (Public)NC
185356Very SatisfiedHigh School (Public)GA
1915189UnsatisfiedHigh School (Private)NC
203309SatisfiedHigh 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

The FREQTAB Procedure

Table of SchoolType by Response
SchoolTypeResponseFrequencyPercent Row
Percent
Column
Percent
Middle School (Private)Very Satisfied5941.8315.7712.05
 Satisfied8232.5421.8511.32
 Neutral11833.6431.4112.51
 Unsatisfied8462.6122.4611.16
 Very Unsatisfied3200.998.509.93
 Total376611.60100.00 
Middle School (Public)Very Satisfied12613.8813.9425.58
 Satisfied18115.5820.0224.91
 Neutral24947.6827.5626.37
 Unsatisfied23647.2826.1331.18
 Very Unsatisfied11183.4412.3634.70
 Total904827.88100.00 
High School (Private)Very Satisfied14594.4918.2329.60
 Satisfied21606.6526.9929.72
 Neutral24227.4630.2625.61
 Unsatisfied13634.2017.0317.98
 Very Unsatisfied5991.857.4818.59
 Total800324.66100.00 
High School (Public)Very Satisfied16154.9813.8732.77
 Satisfied24757.6321.2634.05
 Neutral335910.3528.8535.51
 Unsatisfied30089.2725.8439.68
 Very Unsatisfied11853.6510.1836.78
 Total1164235.87100.00 
TotalVery Satisfied492915.19 100.00
 Satisfied726922.39 100.00
 Neutral945829.14 100.00
 Unsatisfied758123.36 100.00
 Very Unsatisfied32229.93 100.00
 Total32459100.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

StatisticDFValueProb
Chi-Square12505.1446<.0001
Likelihood Ratio Chi-Square12512.2769<.0001
Mantel-Haenszel Chi-Square10.00500.9438
Phi Coefficient 0.1247 
Contingency Coefficient 0.1238 
Cramer's V 0.0720 


Figure 4: Measures of Association

StatisticValueASE 95%
Confidence Limits
Gamma0.00240.0061-0.00970.0144
Kendall's Tau-b0.00180.0046-0.00730.0108
Stuart's Tau-c0.00180.0046-0.00720.0108
Somers' D C|R0.00180.0048-0.00750.0112
Somers' D R|C0.00170.0044-0.00700.0104
Pearson Correlation-0.00040.0055-0.01120.0104
Spearman Correlation0.00180.0056-0.00900.0127
Lambda Asymmetric C|R0.00000.00000.00000.0000
Lambda Asymmetric R|C0.00000.00000.00000.0000
Lambda Symmetric0.00000.00000.00000.0000
Uncertainty Coefficient C|R0.00510.00040.00420.0060
Uncertainty Coefficient R|C0.00600.00050.00500.0070
Uncertainty Coefficient Symmetric0.00550.00050.00460.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)

 Frequency Plot (Grouped Bar Chart)


Figure 6: Mosaic Plot

 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

The FREQTAB Procedure

Frequency
Percent
Row Pct
Col Pct
Table 1 of SchoolType by Response
Controlling for State=GA
SchoolTypeResponse
Very SatisfiedSatisfiedNeutralUnsatisfiedVery UnsatisfiedTotal
Middle School (Private)
146
1.77
15.26
12.17
193
2.34
20.17
11.05
293
3.56
30.62
12.03
243
2.95
25.39
12.19
82
1.00
8.57
9.58
957
11.63
 
 
Middle School (Public)
281
3.41
12.56
23.42
406
4.93
18.14
23.24
625
7.59
27.93
25.67
631
7.67
28.19
31.66
295
3.58
13.18
34.46
2238
27.19
 
 
High School (Private)
369
4.48
17.67
30.75
537
6.52
25.72
30.74
651
7.91
31.18
26.74
357
4.34
17.10
17.91
174
2.11
8.33
20.33
2088
25.37
 
 
High School (Public)
404
4.91
13.70
33.67
611
7.42
20.73
34.97
866
10.52
29.38
35.56
762
9.26
25.85
38.23
305
3.71
10.35
35.63
2948
35.82
 
 
Total
1200
14.58
1747
21.22
2435
29.58
1993
24.21
856
10.40
8231
100.00


Figure 8: CMH Test of No Association

The FREQTAB Procedure


Summary Statistics for SchoolType by Response
Controlling for State

Cochran-Mantel-Haenszel Statistics (Based on Table Scores)
StatisticAlternative HypothesisDFValueProb
1Nonzero Correlation10.00860.9262
2Row Mean Scores Differ3406.7786<.0001
3General Association12508.7656<.0001


Total Sample Size = 32459


Last updated: September 22, 2026