Getting Started with PROC FREQ in SAS: Your Guide to Frequency Analysis

When analyzing categorical data in SAS, one of the most powerful and commonly used procedures is PROC FREQ. Whether you're exploring survey data, customer demographics, or clinical trial results, PROC FREQ helps you understand the distribution and relationships of categorical variables with simplicity and precision.


In this post, we’ll walk through the fundamentals of PROC FREQ, its key options, and practical examples to help you get started.


What is PROC FREQ?

PROC FREQ stands for Procedure Frequency. It's used to:

  • Generate frequency tables
  • Calculate percentages
  • Compute cumulative frequencies
  • Create cross-tabulations (contingency tables)
  • Run chi-square tests and other statistical analyses

This procedure is most effective when working with categorical or ordinal variables.


Basic Syntax

PROC FREQ DATA=your_dataset;
TABLES variable1 variable2; RUN;

Example:

PROC FREQ DATA=sashelp.class;
TABLES sex; RUN;

This code will show how many males and females are in the sashelp.class dataset, along with percentages.


Key Features and Options

1. One-Way Frequency Table

Simple count of each unique value in a variable.

PROC FREQ DATA=sashelp.class;
TABLES age; RUN;

2. Two-Way Tables (Cross-tabulation)

Examine the relationship between two variables.

PROC FREQ DATA=sashelp.class;
TABLES sex*age; RUN;

This creates a two-way table showing the distribution of age within each gender.

3. NLEVELS Option

Gives the number of distinct levels (values) for each variable.

PROC FREQ DATA=sashelp.class NLEVELS;
TABLES sex age; RUN;


4. Table Statement Options

Option

Description

NOCUM

Suppresses cumulative frequency and cumulative percent columns.

NOPERCENT

Suppresses the percent and cumulative percent columns.

NOROW

Suppresses row percentages in a two-way table.

NOCOL

Suppresses column percentages in a two-way table.

LIST

Displays two-way table in list format instead of tabular format.

CROSSLIST

Outputs one row per combination of values (like list), but with statistics.

CHISQ

Performs chi-square tests of association for two-way tables.

FISHER

Performs Fisher's exact test (good for small sample sizes).

EXACT

Requests exact p-values for tests (useful when assumptions of chi-square aren't met).

TREND

Performs Cochran-Armitage trend test (for ordered categories).

EXPECTED

Displays expected cell frequencies under the null hypothesis.

CELLCHI2

Shows chi-square contribution of each cell.

ALL

Displays all available statistics.

MISSING

Includes missing values in frequency calculations.


5. Adding Percentages and Cumulative Stats

By default, PROC FREQ includes:

  • Frequency count
  • Percent
  • Cumulative frequency
  • Cumulative percent

These can be useful to quickly gauge distributions.

Examples

Basic one-way table without cumulative stats:

proc freq data=sashelp.class;
tables sex / nocum; run;

Two-way table with Chi-Square and Expected Values:

proc freq data=sashelp.class;
tables sex*age / chisq expected; run;

Frequency with weights:

proc freq data=mydata;
tables category; weight freq_count;
run;


Export frequency output to dataset:

proc freq data=sashelp.class;
tables age / out=age_freq; run; proc print data=age_freq; run;

Handling Missing Values:

PROC FREQ DATA=your_data; TABLES var1 / MISSING; RUN;
Creating Output Datasets with ODS

You can export the frequency output to a dataset using the OUT= option:

PROC FREQ DATA=sashelp.class;
TABLES sex / OUT=freq_output; RUN; PROC PRINT DATA=freq_output; RUN;

This is helpful when you want to use the results for further processing or reporting.


When Should You Use PROC FREQ?

Use PROC FREQ when:

  • You need descriptive stats for categorical variables.
  • You're exploring data distributions.
  • You want to test independence or associations between categorical variables.
  • You need to validate data (e.g., identify invalid or unexpected categories).

Final Thoughts

PROC FREQ is an essential tool in the SAS programmer’s toolkit. Its simplicity and versatility make it a go-to for data exploration and preliminary statistical analysis. With just a few lines of code, you can uncover patterns, validate data quality, and prepare datasets for deeper analysis.

Whether you're just starting with SAS or are already experienced, mastering PROC FREQ is a foundational step in becoming proficient with categorical data.


💡 Pro Tip:

Pair PROC FREQ with other procedures like PROC MEANS and PROC SGPLOT for a comprehensive data analysis workflow.

Keywords: PROC FREQ in SAS, SAS PROC FREQ tutorial, SAS frequency table

SAS PROC FREQ examples

FAQs: 

How do I use PROC FREQ in SAS for cross-tabulation

What are the best options in PROC FREQ?

Can PROC FREQ handle missing data in SAS?

Post a Comment

0 Comments