Skip to content
AgileLogics
5 min read

PROC FREQ

Prerequisites: PROC MEANS and PROC SUMMARY

PROC FREQ counts how often each value occurs — the first thing to run on any categorical variable.

One-way tables

proc freq data=sashelp.class;
   tables sex;
run;
                      The FREQ Procedure

                                 Cumulative    Cumulative
Sex    Frequency     Percent     Frequency      Percent
---------------------------------------------------------
F             9       47.37             9        47.37
M            10       52.63            19       100.00

Options after a slash change the table: / nocum drops the cumulative columns, / missing counts missing values as a category, and order=freq on the PROC FREQ statement sorts by count.

Two-way tables

An asterisk crosses two variables:

proc freq data=sashelp.class;
   tables sex*age / nopercent norow nocol;
run;

Output (simplified):

Table of Sex by Age

Frequency |  11 |  12 |  13 |  14 |  15 |  16 | Total
----------+-----+-----+-----+-----+-----+-----+------
F         |   1 |   2 |   2 |   2 |   2 |   0 |     9
M         |   1 |   3 |   1 |   2 |   2 |   1 |    10
----------+-----+-----+-----+-----+-----+-----+------
Total         2     5     3     4     4     1      19

Without the options, each cell also shows the overall, row, and column percentages.

Tests and output data sets

  • tables a*b / chisq; adds chi-square tests of association (with a warning when expected counts are too small, as they would be here). / fisher gives Fisher's exact test.
  • tables sex / out=counts; saves the counts and percentages to a data set.
  • tables sex age; produces two separate one-way tables.

Checking data quality

PROC FREQ is the fastest way to find typos in codes: run it on every character variable and look for values like f, Female, and F side by side. tables _character_; does them all at once.