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
Example:
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.
2. Two-Way Tables (Cross-tabulation)
Examine the relationship between two variables.
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.
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:
Two-way table with Chi-Square and Expected Values:
Frequency with weights:
Export frequency output to dataset:
Handling Missing Values:
Creating Output Datasets with ODS
You can export the frequency output to a dataset using the OUT=
option:
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?
0 Comments
If you have any doubt please comment or write us to - datahark12@gmail.com