Psychology 815:Computer Lab #11
Graphing with SAS-graph
November 22, 1996


Objectives:

     1) The linear plot

     2) Bar graphs

     3) Pie charts

Graphing with SAS-GRAPH

It is often helpful to look at the data using various graphs. In addition, graphs and charts are crucial for presentations and publications. This could be a semester-long course in and of itself (there are two big SAS manuals devoted to SAS-GRAPH), however, the basic designs are not too difficult.

Here's the input statement and the data:

input ID CONDITN DEPVAR;

 1   0   45

 2   0   45

 3   0   45

 4   0   45

 5   0   45

 6   0   45

 7   1   56

 8   1   56

 9   1   56

10   1   56

11   1   56

12   1   56

13   2   58

14   2   58

15   2   58

16   2   58

17   2   58

18   2   58

Objective 1: The linear plot

Probably the simplest graph is a linear plot. We'll use the data above for this example. Here is the SAS code to plot the DEPVAR on the vertical axis and the CONDITN on the horizontal axis.

proc gplot;
plot DEPVAR * CONDITN /;
run;


Objective 2: The bar graph

Part a: Bar charts are also commonly used. Let's go back to our Jamaican/U.S. data for the rest of the graphs. The following SAS program will make vertical bar graphs for each age group for the mean externalizing score, which is CBTOTEXT.

proc gchart data= SASUSER.DATA815;
vbar AGEcb /
patternid=midpoint
type=MEAN
sumvar=CBTOText
discrete;
run;

Part b: The following program is the same as the previous one, except that we're also subdividing the age groups by sex (SEXCB).

proc gchart data=SASUSER.DATA815;
vbar SEXCB /
subgroup = SEXCB
group=AGE
type=MEAN
sumvar=CBTOText
DISCRETE;
run;


Objective 3: The pie chart

Of course, no graphing lesson would be complete without the pie-chart. Here it is: The pie slices in this example are frequencies of aggression for each of the four age groups. Don't worry if it seems confusing. Once you see the output, everything will make immediate sense.

proc gchart data=SASUSER.DATA815;
pie AGE /
noheading
percent=OUTSIDE
slice=OUTSIDE
value=OUTSIDE
type=FREQ
freq=AGGRESS
discrete;
run;


Final note: As I said, graphing with SAS can get pretty complex. This is actually the first time that we're teaching SASGRAPH in this course. However, I anticipate that we will be using it quite a bit next semester, so make sure all of this makes sense to you before you leave today.