Documente Academic
Documente Profesional
Documente Cultură
Unit 5
SAS for Data Description
Welcome!
In this reading, the procedures discussed are CHART and PLOT. Also provided is a brief introduction to
using the SAS ANALYST for producing graphics with the SASGRAPH module. The latter are higher quality
graphics than the printer character charts and plots produced with PROCs CHART and PLOT.
Thus, PROCs CHART and PLOT do not provide high quality graphics, but these procedures can be used
effectively in preliminary and summary reports, and to explore graphically, relationships between variables.
TIP - For high quality graphics, consider using SAS to export the information to another platform for
producing graphs. SAS GRAPH can be used with SAS data sets, or data can be exported into spreadsheet
Note - Learning to use the simpler plotting procedures in SAS will also help you to learn to edit programs
Week 12 Page 1 of 13
Week 12 Producing Graphics
2. to understand that it is possible to export SAS data for producing high quality graphics using other
software (such as EXCEL or STATA) ;
4. to understand that it is possible to export a SAS graph directly into another document, such as an
MS WORD document;
Week 12 Page 2 of 13
Week 12 Producing Graphics
• It can be used to produce bar charts, histograms, block, pie, and star charts.
• Many options are available to control grouping, sub-grouping, cumulating values, controlling the axis
• By default, vertical charts are produced; however, horizontal charts can be requested.
• TIP – Requesting horizontal charts will also get you frequencies and percents, neither of which
PROC CHART can also be used to summarize continuous data, in selected settings.
• Provided the number of values is small, PROC CHART can be used to produce charts for
• You can control the number of groupings, and the midpoints for the groupings; or these can be left to a
default algorithm.
• Note - PROC CHART, even when you request a histogram for grouped continuous data, a bar graph is
produced.
Week 12 Page 3 of 13
Week 12 Producing Graphics
It is possible to specify how much space you wish the chart to occupy (full page, half page, etc.) by using the
• HALF PAGE - To get a half page chart size, use PAGESIZE option in the OPTIONS statement and set
it to size 30.
• LARGER THAN FULL PAGE – To produce a chart that is two pages long, specify PAGESIZE 120.
Example
This example is in two parts. The data used is from the cardiopulmonary bypass study, on the sex of the
• Part 2 - Illustrates the use of sub-grouping with the vertical bar chart.
• Note that in this program the PAGESIZE is set at 30 on the OPTIONS statement so as to produce a
Week 12 Page 4 of 13
Week 12 Producing Graphics
FREQUENCY
| *****
15 + *****
| *****
| *****
| *****
| ***** *****
10 + ***** *****
| ***** *****
| ***** *****
| ***** *****
| ***** *****
5 + ***** *****
| ***** ***** *****
| ***** ***** *****
| ***** ***** *****
| ***** ***** ***** *****
--------------------------------------------------------------------
WCTYPE COLD WARM COLD WARM
|------ F ------| |------ M ------| SEX
Week 12 Page 5 of 13
Week 12 Producing Graphics
PROC PLOT is considered an interactive program, so that you can add more plots without restating all of
your options. Many other options are available for controlling the plots. Read the procedures manual.
• Many options are available to control the plot size, scale, reference lines and symbols printed.
• To define a scatterplot a PLOT statement is used. For example, to plot the variable Y against X
PLOT Y * X;
To specify how the graphs fit on a page, use the HPERCENT and VPERCENT options.
• For example, the options of 50 mean that 50% of the linesize, and 50% of the pagesize are allocated
Week 12 Page 6 of 13
Week 12 Producing Graphics
Example
In this example, data on operative time from the cardiopulmonary bypass study is plotted.
• XCLAMP = duration of the cross-clamp time, the actual amount of time the heart is stopped.
• CPBTIME and XCLAMP should be closely associated, as appears on the graphs below.
• The NOMISS option is used so that when data is missing for one variable, the observation is not
used in determining the scale of the plot for the other variable. In this data, one extremely high value
of XCLAMP that was much larger than the total bypass time was changed to missing – we didn’t
want the value of the bypass time for this observation to influence the scale of the plot.
• The HPERCENT and VPERCENT options have been set to 50. This means that 50% of the linesize,
and 50% of the pagesize are allocated for each graph requested.
1st Graph – Illustrates the default options. The letter A is printed for one observation, B for two in
2nd and 3rd Graphs - The next two graphs request that the value of a third variable be used in the
plot. This is useful in determining if there is any obvious difference in operative time for warm or cold
bypass, or for males and females. This does not appear to be the case here.
4th Graph - The final graph illustrates the use of choosing a plotting symbol, in this case an asterisk
(*).
• Note the inclusion of the QUIT; statement in required at the end of PROC PLOT.
Week 12 Page 7 of 13
Week 12 Producing Graphics
Week 12 Page 8 of 13
Week 12 Producing Graphics
A=1, B=2, etc. Plot of CPBTIME*XCLAMP. Plot of CPBTIME*XCLAMP. Symbol is value of SEX.
| |
300 + 300 +
C | C |
P | P |
B | B |
| A | M
T | AA T | MM
I 200 + A I 200 + M
M | A A M | M M
E | A A E | M M
| A A A | M F M
I | A A A A A I | M M F M M
N | A AA A A N | M FF M M
100 + B B A 100 + M M M
M | AA M | MM
I | A A I | M M
N | N |
| |
| |
0 + 0 +
-+----------+----------+----------+----------+ -+----------+----------+----------+----------+
25 50 75 100 125 25 50 75 100 125
XCLAMP XCLAMP
NOTE: 2 obs had missing values. NOTE: 2 obs had missing values. 2 obs hidden.
Plot of CPBTIME*XCLAMP. Symbol is value of WCTYPE. Plot of CPBTIME*XCLAMP. Symbol used is '*'.
| |
300 + 300 +
C | C |
P | P |
B | B |
| W | *
T | CW T | **
I 200 + W I 200 + *
M | W W M | * *
E | C C E | * *
| W W W | * * *
I | C W W W W I | * * * * *
N | W CW C W N | * ** * *
100 + C W C 100 + * * *
M | WC M | **
I | C W I | * *
N | N |
| |
| |
0 + 0 +
-+----------+----------+----------+----------+ -+----------+----------+----------+----------+
25 50 75 100 125 25 50 75 100 125
XCLAMP XCLAMP
NOTE: 2 obs had missing values. 2 obs hidden. NOTE: 2 obs had missing values. 2 obs hidden.
Week 12 Page 9 of 13
Week 12 Producing Graphics
• This is accomplished through the use (in SAS ANALYST) of a SAS graphics module called
SASGRAPH.
• Note - It is also possible to use SASGRAPH without using SAS ANALYST. Here, however, the
• SAS ANALYST has the advantage of point and click capabilities. This is a great advantage over
older versions of SASGRAPH which required the user to be competent in coding selected
• TIP - SAVE the programming statements! When you use SAS ANALYST, SAS produces for you
the programming statements that created the graph. This is nice because you can save the
program. The saved program can then be edited, revised, re-run, whatever!
• SAS ANALYST also allows you to directly edit a graph. Specifically, you can add new text, objects
and lines, etc., and you can do this directly with what is seen on the screen.
• The graph you produce may be exported as an image file and can be edited in another graphics
package. (For example, export the graph as a .bmp file, and then edit it in Paint).
Week 12 Page 10 of 13
Week 12 Producing Graphics
This will allow you to browse for .sas7bdat files. These can be previously saved SAS data files, or
a file in your WORK directory, for the current SAS session.
3. Once you have selected a data file to work with, select Graphs from the menu, and proceed with
the selected graph type.
Week 12 Page 11 of 13
Week 12 Producing Graphics
• To edit and rerun the SAS code with additional features not available in the analyst graph menu:
o You may choose to copy and paste the code to an Enhanced Editor Window (which uses the
color coding features)
• When a graph is in the active window access the interactive edit features from the toolbar:
Week 12 Page 12 of 13
Week 12 Producing Graphics
• To save a graph:
o When the graph window is active, select File > Export as Image
o Choose .gif or .jpeg as the file type if you want to use the file on a web page
o Other file types are available -- check compatibility with other software you wish to use, such
as Adobe photoshop
A saved image file (any of the types mentioned above) can be incorporated directly into a Word document
or a web page.
Week 12 Page 13 of 13