Quantcast
Channel: ListenData
Viewing all articles
Browse latest Browse all 425

SAS : Proc Freq Tutorial

$
0
0
This tutorial explains how to use PROC FREQ.

Create a sample data set
data example1;
input x y $ z;
cards;
6A60
6A70
2A100
2B10
3B67
2C81
3C63
5C55
;
run;

Example 1 : To check the distribution of a categorical variable (Character)
proc freq data = example1;
tables y;
run;
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;
run;
If you want only frequency, not percent distribution and cumulative statistics.
proc freq data = example1;
tables y /nopercent nocum;
run;

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;
run;
Example 4 : Hide Unwanted Statistics in Cross Tabulation
proc freq data = example1;
tables y * x / norow nocol nopercent;
run;
Example 5 : Request Multiple Tables
proc freq data = example1;
tables y * (x z) / norow nocol nopercent;
run;
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 6 : Use WEIGHT Statement

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

Example 8 : Run Chi-Square Analysis
proc freq data = example1 noprint;
tables y * x/chisq;
output All out=temp_chi chisq;
run;

Viewing all articles
Browse latest Browse all 425

Trending Articles