Previous Page | Next Page

The PLOT Procedure

PLOT Statement


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

PLOT plot-request(s) </ option(s)>;

Task Option
Control the axes

Specify the tick-mark values HAXIS= and VAXIS=

Expand the axis HEXPAND and VEXPAND

Specify the number of print positions HPOS= and VPOS=

Reverse the order of the values HREVERSE and VREVERSE

Specify the number of print positions between tick marks HSPACE= and VSPACE=

Assign a value of zero to the first tick mark HZERO and VZERO
Specify reference lines

Draw a line perpendicular to the specified values on the axis HREF= and VREF=

Specify a character to use to draw the reference line HREFCHAR= and VREFCHAR=
Put a box around the plot BOX
Overlay plots OVERLAY
Produce a contour plot

Draw a contour plot CONTOUR

Specify the plotting symbol for one contour level Scontour-level=

Specify the plotting symbol for multiple contour levels SLIST
Label points on a plot

List the penalty and the placement state of the points LIST=

Force the labels away from the origin OUTWARD=

Change default penalties PENALTIES=

Specify locations for the placement of the labels PLACEMENT=

Specify a split character for the label SPLIT=

List all placement states in effect STATES


Required Arguments

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

See Labeling Plot Points with Values of a Variable for more information. 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;

Specifying Variable Lists in Plot Requests

You can use SAS variable lists in plot requests. For example, the following are valid plot requests:

Plot request What is plotted
(a - - d)
a*b a*c a*d b*c b*d
c*d
(x1 - x4)
x1*x2
x1*x3 x1*x4 x2*x3
x2*x4 x3*x4
(_numeric_)
All combinations of numeric variables
y*(x1 - x4)
y*x1
y*x2 y*x4 y*x4

If both the vertical and horizontal specifications request more than one variable and if a variable appears in both lists, then it will not be plotted against itself. For example, the following statement does not plot B*B and C*C:

   plot (a b c)*(b c d);


Specifying Combinations of Variables

The operator in request is either an asterisk (*) or a colon (:). An asterisk combines the variables in the lists to produce all possible combinations of x and y variables. For example, the following plot requests are equivalent:

plot (y1-y2) * (x1-x2);

plot y1*x1 y1*x2 y2*x1 y2*x2;

A colon combines the variables pairwise. Thus, the first variables of each list combine to request a plot, as do the second, third, and so on. For example, the following plot requests are equivalent:

plot (y1-y2) : (x1-x2);

plot y1*x1 y2*x2;


Options

BOX

draws a border around the entire plot, rather than just on the left side and bottom.

Featured in: Overlaying Two Plots
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
Featured in: Producing a Contour Plot
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: For dates, increment can be one of the following:

    DAY

    WEEK

    MONTH

    QTR

    YEAR

    For datetimes, increment can be one of the following:

    DTDAY

    DTWEEK

    DTMONTH

    DTQTR

    DTYEAR

    For times, increment can be one of the following:

    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.  [cautionend]

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.
Featured in: Controlling the Horizontal Axis and Adding a Reference Line, Plotting Data on a Logarithmic Scale, and Plotting Date Values on an Axis
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 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= .

Featured in: Plotting BY Groups
HREFCHAR='character'

specifies the character to use to draw the horizontal reference line.

Default: vertical bar (|)
See also: FORMCHAR= option and HREF=
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.

Tip: LIST is equivalent to LIST=0.
See also: Understanding Penalties
Featured in: Adjusting Labels on a Plot with the PLACEMENT= Option
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.

Featured in: Overlaying Two Plots
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
See also: Understanding Penalties
Featured in: Changing a Default Penalty
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.

Alias: PLACE=
Defaults: 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.
See also: Labeling Plot Points with Values of a Variable
Featured in: Adjusting Labels on a Plot with the PLACEMENT= Option and Adjusting Labeling on a Plot with a Macro
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

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 also: 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';
Default: 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 also: 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='*' .

See also: Labeling Plot Points with Values of a Variable
STATES

lists all the placement states in effect. STATES prints the placement states in the order that you specify them in the PLACE= option.

VAXIS=axis-specification

specifies tick mark values for the vertical axis. VAXIS= follows the same rules as theHAXIS= option.

Featured in: Producing a Contour Plot and Adjusting Labeling on a Plot with a Macro
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.

See also: HEXPAND
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.

See also: HPOS=
VREF=value-specification

draws lines on the plot perpendicular to the specified values on the vertical axis. PROC PLOT includes the values 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= .

Featured in: Controlling the Horizontal Axis and Adding a Reference Line
VREFCHAR='character'

specifies the character to use to draw the vertical reference lines.

Default: horizontal bar (-)
See also: FORMCHAR= option, HREFCHAR=, and VREF=
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.

Previous Page | Next Page | Top of Page