This tutorial explains how to use PROC FREQ in SAS, along with examples.
What PROC FREQ does ?
PROC FREQ is a procedure to summarize categorical variables in SAS. It computes count/frequency and cumulative frequency of categories of a categorical variable. Besides such kind of summary, it can also be used to produce bar charts and tests for association between two categorical variables.
Create a Sample Dataset
Below is a sample SAS program that creates a sample SAS dataset, which will be used to explain examples in this tutorial.
Output:

Example 1 : To verify the distribution of a nominal categorical variable(Character)
Assume you want to observe the frequency distribution of variable 'B'.
The TABLES statement instructs SAS to produce n-way frequency and cross-tabulation tables and calculates the statistics for those tables.
Output:

It answers the question of which category holds the maximum number of cases. Here, the category 'Z' contains the maximum number of values.
Example 2 : To exclude unwanted statistics in the table
Assume that you want to exclude the cumulative frequency and cumulative percent from the table. NOCUM tells SAS to not to return cumulative scores.
Output:

If you wish only for frequency and not percent distribution and cumulative statistics.
Output:

Example 3 : Cross-Tabulation ( 2*2 Table)
Assume you want to see how the variable 'B' is distributed by variable 'A'.
Output:

Example 4 : Display Table in List Format
Suppose you have no interest in the display of output in tabular format and instead you need the final analysis to be displayed in list format (See the image below)
Output:

The forward slash followed by the keyword LIST produces the table in a list styled format.
Example 5 : Suppressing the unwanted statistics in cross tabulation
Output:

The NOROW option suppresses row percentage in cross-tabulation. Likewise, NOCOL option suppresses column percentage.
Example 6 : Get Several Crosstab
Suppose you want to get more than one cross-tabulation. To achieve this, you can use the command given below
The command tables B*(A C); is essentially identical to the command tables B*A B*C; In this case, it produces two tables - B by A and B by C.
Output:

Example 7 : Count of Unique Values
NLEVELS option is used to calculate the number of unique values in a variable.
Output:

Example 8 : Use WEIGHT Statement
Use the WEIGHT statement when counts are already available. It makes PROC FREQ use count data to produce frequency and cross-tabulation tables.
Output:

What PROC FREQ does ?
PROC FREQ is a procedure to summarize categorical variables in SAS. It computes count/frequency and cumulative frequency of categories of a categorical variable. Besides such kind of summary, it can also be used to produce bar charts and tests for association between two categorical variables.
Create a Sample Dataset
Below is a sample SAS program that creates a sample SAS dataset, which will be used to explain examples in this tutorial.
data intellectsage;
input A B $ C;
cards;
8 X 30
8 X 50
1 X 110
3 Y 20
4 Y 37
6 Z 51
1 Z 23
8 Z 45
;
run;
Output:

Example 1 : To verify the distribution of a nominal categorical variable(Character)
Assume you want to observe the frequency distribution of variable 'B'.
proc freq data = intellectsage;
tables B;
run;
The TABLES statement instructs SAS to produce n-way frequency and cross-tabulation tables and calculates the statistics for those tables.
Output:

It answers the question of which category holds the maximum number of cases. Here, the category 'Z' contains the maximum number of values.
Example 2 : To exclude unwanted statistics in the table
Assume that you want to exclude the cumulative frequency and cumulative percent from the table. NOCUM tells SAS to not to return cumulative scores.
proc freq data = intellectsage;
tables B /nocum;
run;
Output:

If you wish only for frequency and not percent distribution and cumulative statistics.
proc freq data = intellectsage;
tables B /nopercent nocum;
run;
Output:

Example 3 : Cross-Tabulation ( 2*2 Table)
Assume you want to see how the variable 'B' is distributed by variable 'A'.
proc freq data = intellectsage;
tables B * A;
run;
Output:

Example 4 : Display Table in List Format
Suppose you have no interest in the display of output in tabular format and instead you need the final analysis to be displayed in list format (See the image below)
proc freq data = intellectsage;
tables B * A / list;
run;
Output:

The forward slash followed by the keyword LIST produces the table in a list styled format.
Example 5 : Suppressing the unwanted statistics in cross tabulation
proc freq data = intellectsage;
tables B * A / norow nocol nopercent;
run;
Output:

The NOROW option suppresses row percentage in cross-tabulation. Likewise, NOCOL option suppresses column percentage.
Example 6 : Get Several Crosstab
Suppose you want to get more than one cross-tabulation. To achieve this, you can use the command given below
proc freq data = intellectsage;
tables B * (A C) / norow nocol nopercent;
run;
The command tables B*(A C); is essentially identical to the command tables B*A B*C; In this case, it produces two tables - B by A and B by C.
Output:

Example 7 : Count of Unique Values
NLEVELS option is used to calculate the number of unique values in a variable.
proc freq data = intellectsage nlevels;
tables B;
run;
Output:

Example 8 : Use WEIGHT Statement
Use the WEIGHT statement when counts are already available. It makes PROC FREQ use count data to produce frequency and cross-tabulation tables.
Data intellectsage;
input present $ postof $ counts;
cards;
Y Y 35
Y N 14
N Y 42
N N 26
;
run;
proc freq data=intellectsage;
tables present*postof;
weight counts;
run;
Output:






