Plotting the Relationship between Variables |
Creating Multiple Plots on Separate Pages |
You can compare trends for different sets of measures by creating multiple plots. To request more than one plot from the same SAS data set, simply specify additional sets of variables in the PLOT statement. The form of the statement is
PLOT vertical-1*horizontal-1 vertical-2*horizontal-2; |
The following program uses the PLOT statement to produce separate plots of the highest and lowest values of the Dow Jones Industrial Average from 1954 to 1998:
options pagesize=40 linesize=76 pageno=1 nodate; proc plot data=highlow; plot LogDowHigh*Year='+' LogDowLow*Year='o' / haxis=1954 to 1998 by 4 box; label LogDowHigh='Log of Highest Value' LogDowLow='Log of Lowest Value' Year='Year Occurred'; title 'Dow Jones Industrial Average Yearly High'; run;
The following output shows the plots:
Creating Multiple Plots on Separate Pages
Dow Jones Industrial Average Yearly High 1 Plot of LogDowHigh*Year. Symbol used is '+'. ---+----+----+----+----+----+----+----+----+----+----+----+--- 10.00 + + | | | | | | L | | o | | g | + | 9.00 + + + o | + | f | | | + | H | | i | ++ | g | + | h 8.00 + +++ + e | + | s | + | t | + | | | V | + | a | + + | l 7.00 + ++ ++ + u | ++++ ++ + + ++++ + | e | + + | | + ++++ | | + | | ++ | | + | 6.00 + + + ---+----+----+----+----+----+----+----+----+----+----+----+--- 1954 1958 1962 1966 1970 1974 1978 1982 1986 1990 1994 1998 Year Occurred
Dow Jones Industrial Average Yearly High 2 Plot of LogDowLow*Year. Symbol used is 'o'. -+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+- 9.00 + + | o| | o | | o | | | L | o | o | oo | g 8.00 + o + | o | o | oo | f | o | | o | L | o | o | o | w 7.00 + oo + e | o | s | o o oo o o o o o o oo | t | o o o | | o o o o o | V | oo o | a | o o | l 6.00 + o o + u | | e | | |o | | | | | | | 5.00 + + -+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+- 1954 1958 1962 1966 1970 1974 1978 1982 1986 1990 1994 1998 Year OccurredThe plots appear on separate pages and use different vertical axes. Different plotting symbols represent the high and low values of the Dow Jones Industrial Average.
Creating Multiple Plots on the Same Page |
You can more easily compare the trends in different sets of measures when the plots appear on the same page. PROC PLOT provides two options that display multiple plots on the same page:
PROC PLOT <DATA=SAS-data-set> VPERCENT=number; |
PROC PLOT <DATA=SAS-data-set> HPERCENT=number; |
To fit two plots on a page, one beneath the other, as in Plots Produced with VPERCENT=50, use VPERCENT=50; to fit three plots, use VPERCENT=33; and so on. To fit two plots on a page, side by side, use HPERCENT=50; to fit three plots, as in Plots Produced with HPERCENT=33, use HPERCENT=33; and so on. Plots Produced with VPERCENT=50 and HPERCENT=33 combines both of these options in the same PLOT statement to create a matrix of plots. Because the VPERCENT= option and the HPERCENT= option appear in the PROC PLOT statement, they affect all plots that are created in the PROC PLOT step.
Plots Produced with VPERCENT=50
Plots Produced with HPERCENT=33
Plots Produced with VPERCENT=50 and HPERCENT=33
The following program uses the VPERCENT= option to display two plots on the same page so that you can compare the trends for the high and the low Dow Jones values:
options pagesize=40 linesize=76 pageno=1 nodate; proc plot data=highlow vpercent=50; plot LogDowHigh*Year='+' LogDowLow*Year='o' / haxis=1954 to 1998 by 4 box; label LogDowHigh='Log of High' LogDowLow='Log of Low' Year='Year Occurred'; title 'Dow Jones Industrial Average Yearly High'; run;
PROC PLOT will use 50% of the vertical space on the page to display each plot.
The following output shows the plots:
Creating Multiple Plots on the Same Page
Dow Jones Industrial Average Yearly High 1 Plot of LogDowHigh*Year. Symbol used is '+'. -+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+- L | | o 9.00 + +++ g | ++ | | ++ | o 8.00 + + ++ ++ + f | + + | | + | H 7.00 + ++ ++ + ++ + + + + ++ ++ + i | ++ ++ ++ + + + + + | g | ++ ++ | h 6.00 ++ + -+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+- 1954 1958 1962 1966 1970 1974 1978 1982 1986 1990 1994 1998 Year Occurred Plot of LogDowLow*Year. Symbol used is 'o'. ---+----+----+----+----+----+----+----+----+----+----+----+--- L | | o 10.00 + + g | | | ooo | o 8.00 + ooo oooo + f | ooo o | | o oo o oooo oooo oooo oooo oooo o | L 6.00 + o ooo o + o | o | w | | 4.00 + + ---+----+----+----+----+----+----+----+----+----+----+----+--- 1954 1958 1962 1966 1970 1974 1978 1982 1986 1990 1994 1998 Year OccurredThe two plots appear on the same page, one beneath the other.
Plotting Multiple Sets of Variables on the Same Axes |
The easiest way to compare trends in multiple sets of measures is to superimpose the plots on one set of axes by using the OVERLAY option in the PLOT statement. The variable names, or variable labels if they exist, from the first plot become the axes labels. Unless you use the HAXIS= option or the VAXIS= option, PROC PLOT automatically scales the axes to best fit all the variables.
The following program uses the OVERLAY option to plot the high and the low Dow Jones Industrial Average values on the same pair of axes:
options pagesize=40 linesize=76 pageno=1 nodate; proc plot data=highlow; plot LogDowHigh*Year='+' LogDowLow*Year='o' / haxis=1954 to 1998 by 4 overlay box; label LogDowHigh='Log of High or Low' Year='Year Occurred'; title 'Dow Jones Industrial Average'; run;
A new label for the variable LogDowHigh is specified because PROC PLOT uses only this variable to label the vertical axis.
The following output shows the plot:
Dow Jones Industrial Average 1 Plot of LogDowHigh*Year. Symbol used is '+'. Plot of LogDowLow*Year. Symbol used is 'o'. ---+----+----+----+----+----+----+----+----+----+----+----+--- | | 10.00 + + | | | | | | L | + | o 9.00 + +o + g | +o | | + o | o | | f | +++o | 8.00 + + +++ oo + H | oo | i | + +o | g | +oo | h | + + | 7.00 + + ++ ++ +++o oo + o | ++ + ++++ o ++ o ++ o | r | + ++++ o oo o o o ooo o o | | +o oo o o oo | L | + ++ o | o 6.00 + +o oo + w | | | o | | | | | 5.00 + + | | ---+----+----+----+----+----+----+----+----+----+----+----+--- 1954 1958 1962 1966 1970 1974 1978 1982 1986 1990 1994 1998 Year Occurred NOTE: 5 obs hidden.The linear trends in the high and low Dow Jones values over the years from 1954 to 1998 are easily noticed.
Note: When the SAS system option OVP is in effect and overprinting is allowed, the plots are superimposed; otherwise, when NOOVP is in effect, PROC PLOT uses the plotting symbol from the first plot to represent points that appear in more than one plot. In such a case, the output includes a message telling you how many observations are hidden.
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.