PLOT Procedure

PLOT Statement

Requests the plots to be produced by PROC PLOT.
Tip: You can use multiple PLOT statements.
Specifying a Plotting Symbol

Controlling the Horizontal Axis and Adding a Reference Line

Overlaying Two Plots

Producing Multiple Plots per Page

Plotting Data on a Logarithmic Scale

Plotting Date Values on an Axis

Producing a Contour Plot

Plotting BY Groups

Adding Labels to a Plot

Adjusting Labels on a Plot with the PLACEMENT= Option

Adjusting Labeling on a Plot with a Macro

Changing a Default Penalty

Syntax

Summary of Optional Arguments

puts a box around the plot.
overlays plots.
Control the axes
specifies the tick-mark values for the horizontal axis.
expands the horizontal axis.
specifies the number of print positions on the horizontal axis.
reverses the order of the values on the horizontal axis.
specifies the distance between tick marks on the horizontal axis.
assigns a value of zero to the first tick mark on the horizontal axis.
specifies the tick-mark values for the vertical axis.
expands the vertical axis.
specifies the number of print positions on the vertical axis.
reverses the order of the values on the vertical axis.
specifies the distance between tick marks on the vertical axis.
assigns a value of zero to the first tick mark on the vertical axis.
Label points on a plot
lists the penalty and the placement state of the points.
forces the labels away from the origin.
changes default penalties.
specifies locations for the placement of the labels.
specifies a split character for the label.
lists all placement states in effect.
Produce a contour plot
draws a contour plot.
specifies the plotting symbol for one contour level.
Produce a countour plot
specifies the plotting symbol for multiple contour levels.
Specify reference lines
draws a line perpendicular to the specified values on the horizontal axis.
specifies a character to use to draw the horizontal reference line.
draws a line perpendicular to the specified values on the vertical axis.
specifies a character to use to draw the vertical reference line.

Required Argument

plot-request(s)
specifies the variables (vertical and horizontal) to plot and the plotting symbol to use to mark the points on the plot.
Each form of plot-request(s) supports a label variable. A label variable is preceded by a dollar sign ($) and specifies a variable whose values label the points on the plot. For example:
plot y*x $ label-variable
plot y*x='*' $ label-variable
For more information, see Labeling Plot Points with Values of a Variable. In addition, see Adding Labels to a Plot and all the examples that follow it.
The plot-request(s) can be one or more of the following:
vertical*horizontal <$ label-variable>
specifies the variable to plot on the vertical axis and the variable to plot on the horizontal axis.
For example, the following statement requests a plot of Y by X:
plot y*x;
Y appears on the vertical axis, X on the horizontal axis.
This form of the plot request uses the default method of choosing a plotting symbol to mark plot points. When a point on the plot represents the values of one observation in the data set, PROC PLOT puts the character A at that point. When a point represents the values of two observations, the character B appears. When a point represents values of three observations, the character C appears, and so on, through the alphabet. The character Z is used for the occurrence of 26 or more observations at the same printing position.
vertical*horizontal='character' <$ label-variable>
specifies the variables to plot on the vertical and horizontal axes and specifies a plotting symbol to mark each point on the plot. A single character is used to represent values from one or more observations.
For example, the following statement requests a plot of Y by X, with each point on the plot represented by a plus sign (+):
plot y*x='+';
vertical*horizontal=variable <$ label-variable>
specifies the variables to plot on the vertical and horizontal axes and specifies a variable whose values are to mark each point on the plot. The variable can be either numeric or character. The first (left-most) nonblank character in the formatted value of the variable is used as the plotting symbol (even if more than one value starts with the same letter). When more than one observation maps to the same plotting position, the value from the first observation marks the point. For example, in the following statement GENDER is a character variable with values of FEMALE and MALE; the values F and M mark each observation on the plot.
plot height*weight=gender;

Optional Arguments

BOX
draws a border around the entire plot, rather than just on the left side and bottom.
CONTOUR<=number-of-levels>
draws a contour plot using plotting symbols with varying degrees of shading where number-of-levels is the number of levels for dividing the range of variable. The plot request must be of the form vertical*horizontal=variable where variable is a numeric variable in the data set. The intensity of shading is determined by the values of this variable.
When you use CONTOUR, PROC PLOT does not plot observations with missing values for variable.
Overprinting, if it is enabled by the OVP system option, is used to produce the shading. Otherwise, single characters varying in darkness are used. The CONTOUR option is most effective when the plot is dense.
Default:10
Range:1-10
HAXIS=axis-specification
specifies the tick-mark values for the horizontal axis.
  • For numeric values, axis-specification is either an explicit list of values, a BY increment, or a combination of both:
    n <…n>
    BY increment
    n TO n BY increment
    The values must be in either ascending or descending order. Use a negative value for increment to specify descending order. The specified values are spaced evenly along the horizontal axis even if the values are not uniformly distributed. Numeric values can be specified in the following ways:
    HAXIS= value
    Comments
    10 to 100 by 5
    Values appear in increments of 5, starting at 10 and ending at 100.
    by 5
    Values are incremented by 5. PROC PLOT determines the minimum and maximum values for the tick marks.
    10 100 1000 10000
    Values are not uniformly distributed. This specification produces a logarithmic plot. If PROC PLOT cannot determine the function implied by the axis specification, it uses simple linear interpolation between the points. To determine whether PROC PLOT correctly interpolates a function, you can use the DATA step to generate data that determines the function and see whether it appears linear when plotted. See Plotting Data on a Logarithmic Scale for an example.
    1 2 10 to 100 by 5
    A combination of the previous specifications.
  • For character variables, axis-specification is a list of unique values that are enclosed in quotation marks:
    'value-1' <…'value-n'>
    For example,
    haxis='Paris' 'London' 'Tokyo'
    The character strings are case sensitive. If a character variable has an associated format, then axis-specification must specify the formatted value. The values can appear in any order.
  • For axis variables that contain date-time values, axis-specification is either an explicit list of values or a starting and an ending value with an increment specified:
    'date-time-value'i <…'date-time-value'i>
    'date-time-value'i TO <…'date-time-value'i>
    <BY increment>
    'date-time-value'i
    any SAS date, time, or datetime value described for the SAS functions INTCK and INTNX. The suffix i is one of the following:
    D date
    T time
    DT datetime
    increment
    one of the valid arguments for the INTCK or INTNX functions. increment can be one of the following:
    For dates
    For datetimes
    For times
    DAY
    WEEK
    MONTH
    QTR
    YEAR
    DTDAY
    DTWEEK
    DTMONTH
    DTQTR
    DTYEAR
    HOUR
    MINUTE
    SECOND
    For example,
       haxis='01JAN95'd to '01JAN96'd       
       by month     
    
    haxis='01JAN95'd to '01JAN96'd       
       by qtr
    Note: You must use a FORMAT statement to print the tick-mark values in an understandable form.
Interaction:You can use the HAXIS= and VAXIS= options with the VTOH= option to equate axes. If your data is suitable, then use HAXIS=BY n and VAXIS=BY n with the same value for n and specify a value for the VTOH= option. The number of columns that separate the horizontal tick marks is nearly equal to the number of lines that separate the vertical tick marks times the value of the VTOH= option. In some cases, PROC PLOT cannot simultaneously use all three values and changes one or more of the values.
HEXPAND
expands the horizontal axis to minimize the margins at the sides of the plot and to maximize the distance between tick marks, if possible.
HEXPAND causes PROC PLOT to ignore information about the spacing of the data. Plots produced with this option waste less space but can obscure the nature of the relationship between the variables.
HPOS=axis-length
specifies the number of print positions on the horizontal axis. The maximum value of axis-length that allows a plot to fit on one page is three positions less than the value of the LINESIZE= system option because there must be space for the procedure to print information next to the vertical axis. The exact maximum depends on the number of characters that are in the vertical variable's values. If axis-length is too large to fit on a line, then PROC PLOT ignores the option.
HREF=value-specification
draws lines on the plot perpendicular to the specified values on the horizontal axis. PROC PLOT includes the values that you specify with the HREF= option on the horizontal axis unless you specify otherwise with the HAXIS= option.
For the syntax for value-specification, see HAXIS=axis-specification .
HREFCHAR='character'
specifies the character to use to draw the horizontal reference line.
HREVERSE
reverses the order of the values on the horizontal axis.
HSPACE=n
specifies that a tick mark will occur on the horizontal axis at every nth print position, where n is the value of HSPACE=.
HZERO
assigns a value of zero to the first tick mark on the horizontal axis.
Interaction:PROC PLOT ignores HZERO if the horizontal variable has negative values or if the HAXIS= option specifies a range that does not begin with zero.
LIST<=penalty-value>
lists the horizontal and vertical axis values, the penalty, and the placement state of all points plotted with a penalty greater than or equal to penalty-value. If no plotted points have a penalty greater than or equal to penalty-value, then no list is printed.
OUTWARD='character'
tries to force the point labels outward, away from the origin of the plot, by protecting positions next to symbols that match character that are in the direction of the origin (0,0). The algorithm tries to avoid putting the labels in the protected positions, so they usually move outward.
Tip:This option is useful only when you are labeling points with the values of a variable.
OVERLAY
overlays all plots that are specified in the PLOT statement on one set of axes. The variable names, or variable labels if they exist, from the first plot are used to label the axes. Unless you use the HAXIS= or the VAXIS= option, PROC PLOT automatically scales the axes in the way that best fits all the variables.
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.
PENALTIES<(index-list)>=penalty-list
changes the default penalties. The index-list provides the positions of the penalties in the list of penalties. The penalty-list contains the values that you are specifying for the penalties that are indicated in the index-list. The index-list and the penalty-list can contain one or more integers. In addition, both index-list and penalty-list accept the form: value TO value
PLACEMENT=(expression(s))
controls the placement of labels by specifying possible locations of the labels relative to their coordinates. Each expression consists of a list of one or more suboptions (H=, L=, S=, or V=) that are joined by an asterisk (*) or a colon (:). PROC PLOT uses the asterisk and colon to expand each expression into combinations of values for the four possible suboptions. The asterisk creates every possible combination of values in the expression list. A colon creates only pairwise combinations. The colon takes precedence over the asterisk. With the colon, if one list is shorter than the other, then the values in the shorter list are reused as necessary.
Use the following suboptions to control the placement:
H=integer(s)
specifies the number of horizontal spaces (columns) to shift the label relative to the starting position. Both positive and negative integers are valid. Positive integers shift the label to the right; negative integers shift it to the left. For example, you can use the H= suboption in the following way:
place=(h=0 1 -1 2 -2)
You can use the keywords BY ALT in this list. BY ALT produces a series of numbers whose signs alternate between positive and negative and whose absolute values change by one after each pair. For example, the following PLACE= specifications are equivalent:
place=(h=0 -1 to -3 by alt)  
place=(h=0 -1 1 -2 2 -3 3)
If the series includes zero, then the zero appears twice. For example, the following PLACE= options are equivalent:
place=(h= 0 to 2 by alt)  
place=(h=0 0 1 -1 2 -2)
Default:H=0
Range:−500 to 500
L=integer(s)
specifies the number of lines onto which the label can be split.
Default:L=1
Range:1-200
S=start-position(s)
specifies where to start printing the label. The value for start-position can be one or more of the following:
CENTER
the procedure centers the label around the plotting symbol.
RIGHT
the label starts at the plotting symbol location and continues to the right.
LEFT
the label starts to the left of the plotting symbol and ends at the plotting symbol location.
Default:CENTER
V=integer(s)
specifies the number of vertical spaces (lines) to shift the label relative to the starting position. V= behaves the same as the H= suboption, described earlier.
A new expression begins when a suboption is not preceded by an operator. Parentheses around each expression are optional. They make it easier to recognize individual expressions in the list. However, the entire expression list must be in parentheses, as shown in the following example. The following table shows how this expression is expanded and describes each placement state.
  	place=((v=1)
          (s=right left : h=2 -2)
          (v=-1)
          (h=0 1 to 2 by alt * v=1 -1)
          (l=1 to 3 * v=1 to 2 by alt *
           h=0 1 to 2 by alt))
Each combination of values is a placement state. The procedure uses the placement states in the order in which they appear in the placement states list, so specify your most preferred placements first. For each label, the procedure tries all states, then it uses the first state that places the label with minimum penalty. When all labels are initially placed, the procedure cycles through the plot multiple times, systematically refining the placements. The refinement step tries to both minimize the penalties and to use placements nearer to the beginning of the states list. However, PROC PLOT uses a heuristic approach for placements, so the procedure does not always find the best set of placements.
Expanding an Expression List into Placement States
Expression
Placement State
Meaning
(V=1)
S=CENTER L=1 H=0 V=1
Center the label, relative to the point, on the line above the point. Use one line for the label.
(S=RIGHT LEFT : H=2 −2)
S=RIGHT L=1 H=2 V=0
Begin the label in the second column to the right of the point. Use one line for the label.
S=LEFT L=1 H=−2 V=0
End the label in the second column to the left of the point. Use one line for the label.
(V=−1)
S=CENTER L=1 H=0 V=− 1
Center the label, relative to the point, on the line below the point. Use one line for the label.
(H=0 1 to 2 BY ALT * V=1 −1)
S=CENTER L=1 H=0 V=1
Center the label, relative to the point, on the line above the point.
S=CENTER L=1 H=0 V=−1
Center the label, relative to the point, on the line below the point.
S=CENTER L=1 H=1 V=1
From center, shift the label one column to the right on the line above the point.
S=CENTER L=1 H=1 V=−1
From center, shift the label one column to the right on the line below the point.
S=CENTER L=1 H=−1 V=1
From center, shift the label one column to the left on the line above the point.
S=CENTER L=1 H=− 1 V=−1
From center, shift the label one column to the left on the line below the point.
S=CENTER L=1 H=2 V=1 S=CENTER L=1 H=2 V=−1
From center, shift the labels two columns to the right, first on the line above the point, then on the line below.
S=CENTER L=1 H=−2 V=1
S=CENTER L=1 H=−2 V=−1
From center, shift the labels two columns to the left, first on the line above the point, then on the line below.
(L=1 to 3 * V=1 to 2 BY ALT * H=0 1 to 2 BY ALT)
S=CENTER L=1 H=0 V=1
Center the label, relative to the point, on the line above the point. Use one line for the label.
S=CENTER L=1 H=1 V=1 S=CENTER L=1 H=−1 V=1 S=CENTER L=1 H=2 V=1 S=CENTER L=1 H=−2 V=1
From center, shift the label one or two columns to the right or left on the line above the point. Use one line for the label.
S=CENTER L=1 H=0 V=−1
Center the label, relative to the point, on the line below the point. Use one line for the label.
S=CENTER L=1 H=1 V=−1 S=CENTER L=1 H=−1 V=−1 S=CENTER L=1 H=2 V=−1 S=CENTER L=1 H=−2 V=−1
From center, shift the label one or two columns to the right and the left on the line below the point.
.
Use the same horizontal shifts on the line two lines above the point and on the line two lines below the point.
S=CENTER L=1 H=− 2 V=−2
S=CENTER L=2 H=0 V=1
Repeat the whole process splitting the label over two lines. Then repeat it splitting the label over three lines.
S=CENTER L=3 H=− 2 V=−2
Alias:PLACE=
Default:There are two defaults for the PLACE= option. If you are using a blank as the plotting symbol, then the default placement state is PLACE=(S=CENTER : V=0 : H=0 : L=1), which centers the label. If you are using anything other than a blank, then the default is PLACE=((S=RIGHT LEFT : H=2 −2) (V=1 −1 * H=0 1 -1 2 -2)). The default for labels placed with symbols includes multiple positions around the plotting symbol so the procedure has flexibility when placing labels on a crowded plot.
Tip:Use the STATES option to print a list of placement states.
Scontour-level='character-list'
specifies the plotting symbol to use for a single contour level. When PROC PLOT produces contour plots, it automatically chooses the symbols to use for each level of intensity. You can use the S= option to override these symbols and specify your own. You can include up to three characters in character-list. If overprinting is not allowed, then PROC PLOT uses only the first character.
For example, to specify three levels of shading for the Z variable, use the following statement:
plot y*x=z /
    contour=3 s1='A' s2='+' s3='X0A';
You can also specify the plotting symbols as hexadecimal constants:
plot y*x=z /
    contour=3 s1='7A'x  s2='7F'x s3='A6'x;
This feature was designed especially for printers where the hexadecimal constants can represent gray scale fill characters.
Range:1 to the highest contour level (determined by the CONTOUR option).
See:SLIST= and CONTOUR
SLIST='character-list-1' <…'character-list-n'>
specifies plotting symbols for multiple contour levels. Each character-list specifies the plotting symbol for one contour level: the first character-list for the first level, the second character-list for the second level, and so on. For example:
plot y*x=z /    
     contour=5  slist='.' ':' '!' '=' '+O';
If you omit a plotting symbol for each contour level, then PROC PLOT uses the default symbols:
slist='.' ',' '-' '=' '+' 'O' 'X'       'W' '*' '#' 
Restriction:If you use the SLIST= option, then it must be listed last in the PLOT statement.
See:Scontour-level= and CONTOUR=
SPLIT='split-character'
when labeling plot points, specifies where to split the label when the label spans two or more lines. The label is split onto the number of lines that is specified in the L= suboption to the PLACEMENT= option. If you specify a split character, then the procedure always splits the label on each occurrence of that character, even if it cannot find a suitable placement. If you specify L=2 or more but do not specify a split character, then the procedure tries to split the label on blanks or punctuation but will split words if necessary.
PROC PLOT shifts split labels as a block, not as individual fragments (a fragment is the part of the split label that is contained on one line). For example, to force This is a label to split after the a , change it to This is a*label and specify SPLIT='*' .
STATES
lists all the placement states in effect. STATES prints the placement states in the order in which you specify them in the PLACE= option.
VAXIS=axis-specification
specifies tick mark values for the vertical axis. VAXIS= follows the same rules as the HAXIS= option.
VEXPAND
expands the vertical axis to minimize the margins above and below the plot and to maximize the space between vertical tick marks, if possible.
VPOS=axis-length
specifies the number of print positions on the vertical axis. The maximum value for axis-length that allows a plot to fit on one page is eight lines less than the value of the SAS system option PAGESIZE= because you must allow room for the procedure to print information under the horizontal axis. The exact maximum depends on the titles that are used, whether plots are overlaid, and whether CONTOUR is specified. If the value of axis-length specifies a plot that cannot fit on one page, then the plot spans multiple pages.
VREF=value-specification
draws lines on the plot perpendicular to the specified values on the vertical axis. PROC PLOT includes the values that you specify with the VREF= option on the vertical axis unless you specify otherwise with the VAXIS= option. For the syntax for value-specification, see HAXIS=axis-specification .
VREFCHAR='character'
specifies the character to use to draw the vertical reference lines.
VREVERSE
reverses the order of the values on the vertical axis.
VSPACE=n
specifies that a tick mark will occur on the vertical axis at every nth print position, where n is the value of VSPACE=.
VZERO
assigns a value of zero to the first tick mark on the vertical axis.
Interaction:PROC PLOT ignores the VZERO option if the vertical variable has negative values or if the VAXIS= option specifies a range that does not begin with zero.