Producing a Simple Scatter Plot - SAS Programming

Suppose you are interested in the relationship between systolic blood pressure (SBP) and diastolic blood pressure (DBP).One useful way to visually detect a relationship between these variables is to plot one versus the other.If you choose to place SBP on the X axis and DBP on the Y axis, use the following SAS statements to create such a plot:

Example

DATA BLOCKEG;
SET CLINICAL (KEEP=DATE ROUTINE SBP);
YEAR=YEAR(DATE);
RON;
PROC CHART DATA=BLOCKEG;
TITLE 'Example Of a BLOCK CHART';
BLOCK YEAR / GROUP=ROUTINE DISCRETE; 0
BLOCK YEAR / GROUP*ROUTINE SUMVAR=SBP TYPE=MEAN DISCRETE; 2
FORMAT SBP 5.;
RON;

Note that even though these basic plots are typically called X-Y plots,the PLOT statement lists the Y axis variable first and then the X axis variable (Y=DBP, X=SBP.) Be careful!The very basic output from this simple example follows. Like PROC CHART, settings for PAGESIZE and LINESIZE affect the scales and spacing of the plot points.

Output from Example- Producing a Simple Scatter Plot

Output from Example- Producing a Simple Scatter Plot

It appears from this plot that there is a relationship between the two measures of blood pressure—the higher the systolic blood pressure, the higher the diastolic blood pressure.Notice the use of letters (A, B, C, etc.) as plotting symbols. While this seems strange at first, it is quite useful.Because the program is attempting to plot a graph using a character printer, plotting symbols can only be placed in discrete positions on the page,typically with a resolution of 10 characters per inch horizontally and 6 lines per inch vertically.

With this resolution, two data points that occupy the same position on the graph, or even data points that are fairly close together, wind up in the same print position.By default,PROC PLOT uses the convention of assigning 'A' for 1 data point,'B' for 2, etc.That way, you can see that a single plot position may represent more than one data point.If there are more than 26 points at a given plot position, PROC PLOT will use the letter 'Z' and indicate on the output that there were n hidden observations,where n is the number of data points in excess of 26. A PLOT statement like the one shown here, produces a single Y by X graph:

PLOT y_variable*x_variable;

If you want to produce multiple plots, you can use one of the following forms:

PLOT A*B C*D;
PLOT (A B C)*X;
PLOT (A B C)*(D E F);

The first PLOT request generates two graphs: one of A by B, the other of C by D.The second request generates three plots:A by X; B by X; and C by X. Finally, the third PLOT request produces graphs of all the variables in the first list by every variable in the second list:

A by D B by D C by D
A by E B by E C by E
A by FB by F C by F

Another way to specify plots (new with Release 6.07) is a plot request of the form:

PLOT (A B C) : (D E F);

The colon placed between the two lists, specifies that you want a plot of each variable in the first list (on the Y axis) paired with the corresponding positional variable in the second list(on the X axis). In the code immediately above, three plots (A by D, B by E, and C by F) are produced.

The Interactive Nature of PROC PLOT

PROC PLOT is one of the SAS System's interactive procedures. When you are running SAS software interactively using display manager you can submit a PLOT statement, then return to the Program Editor window and submit another PLOT statement, without another PROC PLOT statement (even after a RUN statement is executed).

When you need to produce multiple plots on the same data set,it is much more efficient to simply submit additional PLOT statements than to continually start the procedure over again with additional PROC PLOT statements. Restart PROC PLOT only if you want new options to be in effect or to plot data from a different data set.

Because of this interactive feature of PROC PLOT, display manager indicates that your procedure is still running,even though the current output is completely displayed.This message tells you that you are free to submit another request. To turn off this procedure, you must do one of the following: run another procedure; run a DATA step; submit a QUIT statement (enter the single statement QUIT; in your Program Editor window and submit it.)


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics