'proc chart' and 'proc freq'


proc chart is used to construct histograms for continuous variables or bar charts for categorical (or discrete) variables.

proc freq is used to produce frequency tables (categorical data only) 

Histograms

 

 

proc chart data=name;

vbar varl var2;

run;

vbar tells SAS to produce a vertical bar chart/histogram. To produce a horizontal bar chart/histogram replace vbar with hbar.

Recall the Dixon and Massey example data set from the first module [Note: The 'dixonmassey' data set is from Dixon WJ and Massey FJ Jr.,: Introduction to Statistical Analysis, Fourth Edition, McGraw Hill Book Company, 1983.] 

 

data dixonmassey;

input Obs chol52 chol62 age cor dchol agelt50;

datalines;

;

Suppose we would like histograms of cholesterol in 1952, and a bar chart of coronary events.

proc chart;

vbar chol52;

run;

To plot this horizontally you would use the following: 

proc chart;

hbar chol52;

run;

 

You might notice these plots are not terribly attractive. You can instead use proc gchart, which operates in the same way but produces nicer looking figures.

proc gchart;

vbar chol52;

run;

 

 

 

proc gchart;

vbar chol52;

run;

 

Frequency Tables

To generate frequency tables you can use the generic commands:

 

proc freq data=name;

tables var;

run;

 

Example:

 

proc freq;

tables cor;

run;

 

 

Bar Charts

The discrete command tells SAS that the variable is discrete and to create a bar chart. Note that either vbar or hbar can be used.

 

The generic form is:

proc chart data=name;

hbar var/discrete;

run;

 

Example:

proc chart;

hbar cor/discrete;

run;

 

 

Here is what it would look like with gchart.

proc gchart;

vbar cor/discrete;

run;