SAS : Proc Freq Tutorial

This tutorial explains how to use PROC FREQ with examples. The PROC FREQ is one of the most frequently used SAS procedures which helps to calculate count/frequency and cumulative frequency.

Create a sample data set
data example1;
input x y $ z;
6 A 60
6 A 70
2 A 100
2 B 10
3 B 67
2 C 81
3 C 63
5 C 55

Example 1 : To check the distribution of a categorical variable (Character)
proc freq data = example1;
tables y;
The TABLES statements tells SAS to return one-way to n-way frequency and crosstabulation tables and computes the statistics for these tables.

Output : PROC FREQ

Example 2 : To remove unwanted statistics in the table

Suppose you do not want cumulative frequency and percent to be displayed in the table.
proc freq data = example1;
tables y /nocum;
If you want only frequency, not percent distribution and cumulative statistics.
proc freq data = example1;
tables y /nopercent nocum;

Example 3 : Cross Tabulation ( 2*2 Table)

Suppose you want to see the distribution of variable "y" by variable "x".
proc freq data = example1;
tables y * x;
Proc Freq Output
The output of the above SAS program is shown in the image above.

Example 4 : Show Table in List Form

Suppose you do not want output to be shown in tabular form. Instead, you want final analysis to be displayed in list form (See the image below)
proc freq data = example1;
tables y * x / list;
The forward slash followed by LIST keyword produces the list styled table.

Example 5 : Hide Unwanted Statistics in Cross Tabulation
proc freq data = example1;
tables y * x / norow nocol nopercent;
Example 6 : Request Multiple Tables
proc freq data = example1;
tables y * (x z) / norow nocol nopercent;
The tables y*(x z) statement is equivalent to tables y*x y*z statement.
Example - tables (a b)*(c d); is equivalent to tables a*c b*c a*d b*d;

Example 7 : Use WEIGHT Statement

The WEIGHT statement is used when we already have the counts.
Data example2;
input pre $ post $ count;
Yes Yes 30
Yes No 10
No Yes 40
No No 20
proc freq data=example2;
tables pre*post;
weight count;run;
Example 8 : Store result in a SAS dataset
proc freq data = example1;
tables y *x / out = temp;
The OUT option is used to store result in a data file.

Example 9 : Run Chi-Square Analysis

The CHISQ option provides chi-square tests of homogeneity or independence and measures of association between two categorical variables.  Also it helps to identify the statistically significant categorical variables that we should include in our predictive model. All the categorical variables with a chi-square value less than or equal to 0.05 are kept.
proc freq data = example1 noprint;
tables y * x/chisq;
output All out=temp_chi chisq;

SAS Tutorials : 100 Free SAS Tutorials

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

9 Responses to "SAS : Proc Freq Tutorial"

  1. Good explaination!

  2. Great tutorial...
    could you also explain more on 'WEIGHT statement'

  3. Replies
    1. Good question bank and explanations.Keep posting!!

  4. Good Work, luck to stumble upon your site.


Next → ← Prev