Example Program and Statement Details

Example Graph

The following graph was generated by the Example Program:
Example Graph with Layout Gridded

Example Program

The GRIDDED layout offers the best way to nest a table of information inside another layout. In the GRIDDED layout, you can control the content, text justification, and fonts of columns. Because this example nests the GRIDDED layout within an OVERLAY layout, you can control where it appears within the plot area. The AUTOALIGN= option enables you to specify a prioritized list of possible positions where the layout should be drawn. The position actually used is the first one that avoids collision with the histogram. Also, the GRIDDED layout is set to be opaque so that the grid lines do not show through.
This example also illustrates a reusable template in the sense that it works for any numeric variable specified by the dynamic variable VAR. Also, SGE functions for computing the N, MEAN, STDDEV of the variable are used in the table to compute the statistics as the template is executed.
proc template;
 define statgraph inset;
  dynamic VAR;
  begingraph;
   entrytitle "Distribution of " VAR;
   layout overlay / yaxisopts=(griddisplay=on);
    histogram VAR / scale=percent;
    layout gridded / columns=2
        autoalign=(topleft topright) border=true
        opaque=true backgroundcolor=GraphWalls:color;
     entry halign=left "N";
     entry halign=left eval(strip(put(n(VAR),12.0)));
     entry halign=left "Mean";
     entry halign=left eval(strip(put(mean(VAR),12.2)));
     entry halign=left "Std Dev";
     entry halign=left eval(strip(put(stddev(VAR),12.2)));
    endlayout;
   endlayout;
  endgraph;
 end;
run;

proc sgrender data=sashelp.cars template=inset;
   dynamic VAR="Weight";
run;

Statement Summary

A GRIDDED layout is commonly used to create small tables of text that are nested within other layouts. The layout might also be used to span and center a single entry (a legend, for example) across a set of grids. Or it might be used to display a grid of graphs when there is no need to scale axis data ranges or align graphs across grid cells.
The GRIDDED layout automatically decides how much area to allocate to cell contents:
  • text items have a fixed size based on the amount of text and the font properties
  • graphs take up the remaining space.
The layout’s grid size is determined by the COLUMNS= and ROWS= options. The resulting columns and rows can be separated by areas called “gutters,” which are controlled by the COLUMNGUTTER= and ROWGUTTER= options.
By default, the results of the GTL-statements are placed into the grid sequentially from left to right, wrapping to a new row each time the current row is filled. You can use the ORDER= option to fill cells from top to bottom down a column. In that case, the layout cells wrap to a new column each time the current column is filled.

Options

Statement Option
Description
Specifies whether this layout is automatically aligned within its parent when nested within an overlay-type or region layout.
Specifies the color of the layout background.
Specifies whether a border is drawn around the layout.
Specifies the properties of the border line.
Specifies the amount of empty space between the columns.
Specifies the number of columns in the layout.
Specifies this layout’s horizontal alignment within its parent when nested within an overlay-type or region layout.
Specifies whether the layout appears inside or outside the plot area when nested within an overlay-type layout.
Specifies whether the layout background is opaque.
Specifies whether cells are populated using column priority or row priority.
Specifies the amount of extra space that is added inside the layout border.
Specifies the amount of empty space between the rows.
Specifies the number of rows in the layout.
Specifies whether fonts in the layout are scaled when the size of the output is reduced.
Specifies this layout’s vertical alignment within its parent when nested within an overlay-type or region layout.
AUTOALIGN=NONE | AUTO | (location-list)
specifies whether this layout is automatically aligned within its parent when nested within an overlay-type or region layout. For more information about how child positions are determined in an overlay-type or region layout, see the LAYOUT OVERLAY’s Statement Summary.
Default: NONE
NONE
Do not automatically align this layout within its parent layout. This layout’s position within its parent layout is therefore set by the HALIGN= and VALIGN= options.
AUTO
Available only if the parent layout contains a scatter plot; ignored otherwise. Within the parent layout, attempt to center this layout in the area that is farthest from any surrounding data point markers.
(location-list)
Within the parent layout, restrict this layout’s possible locations to those locations in the specified location-list, and use the location-list position that least collides with the parent layout’s other graphics features. The location-list is blank-separated and can contain any of these locations: TOPLEFT, TOP, TOPRIGHT, LEFT, CENTER, RIGHT, BOTTOMLEFT, BOTTOM, and BOTTOMRIGHT.
Restriction: This option is available only when this layout statement is nested within an overlay-type or region layout. This option is ignored if this statement is the outermost layout or if the parent layout is not an overlay-type or region layout.
Interaction: If this option is enabled, it overrides the HALIGN= and VALIGN= options.
Interaction: This option is ignored if LOCATION=OUTSIDE.
BACKGROUNDCOLOR=style-reference | color
specifies the color of the layout background.
Default: The GraphBackground:Color style reference.
style-reference
A reference in the form style-element:style-attribute. Only the style-attribute named COLOR is used.
Interaction: OPAQUE=TRUE must be in effect for the color to be seen. By default, OPAQUE=FALSE.
BORDER=boolean
specifies whether a border is drawn around the layout.
Default: FALSE
Interaction: If this option is set to FALSE, the BORDERATTRS option is ignored.
BORDERATTRS=style-element | style-element (line-options) | (line-options)
specifies the attributes of the border line around the layout. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The GraphBorderLines style element.
Interaction: BORDER=TRUE must be set for this option to have any effect.
COLUMNGUTTER=dimension
specifies the amount of empty space between the columns.
Default: 0
If there are n columns, then there are n-1 gutters.
COLUMNS=integer
specifies the number of columns in the layout.
Default: If ORDER=ROWMAJOR, the default is 1. If ORDER=COLUMNMAJOR, as many columns are created as needed to satisfy the ROWS= request.
Restriction: Assuming ORDER=ROWMAJOR, if COLUMNS=n and there are m cells defined, and n > m, then only m columns are created (there are n - m cells with zero size).
This option is used to create a grid with a fixed number of columns, without concern for how many rows. For example, the following settings ensure that columns 1 and 2 in the first row are filled with content, as shown in the figure:
layout gridded / columns=2 order=rowmajor border=true ;
  entry '1' /border=true;
  entry '2' /border=true;
  entry '3' /border=true;
endlayout; 
grid with set number of columns
HALIGN=CENTER | LEFT | RIGHT | number
specifies this layout’s horizontal alignment within its parent when nested within an overlay-type or region layout. For more information about how child positions are determined in an overlay-type or region layout, see the LAYOUT OVERLAY’s Statement Summary.
Default: CENTER
Range: A number specification can range from 0 to 1. The number represents a fraction of the parent container’s width, where 0 is all the way to the left and 1 is all the way to the right.
Restriction: This option is available only when this statement is nested within an overlay-type or region layout. It is ignored if this statement is the outermost layout or if the parent layout is not an overlay-type or region layout.
Interaction: For a number setting to take effect, LOCATION=INSIDE must be set. A number setting is invalid on this option when LOCATION=OUTSIDE.
Interaction: If the AUTOALIGN= option is enabled, this option is ignored.
LOCATION=INSIDE | OUTSIDE
specifies whether the legend appears inside or outside the plot area when nested within an overlay-type layout.
Default: INSIDE
Restriction: This option has effect only when the GRIDDED layout block appears within an overlay-type layout. For more information about how child positions are determined in an overlay-type layout, see the LAYOUT OVERLAY’s Example Program and Statement Details.
Interaction: If this option is set to OUTSIDE, the HALIGN= and VALIGN= options must specify a keyword (LEFT, RIGHT, or CENTER). The number setting for the alignment is invalid when the layout is positioned outside of the plot area.
Interaction: The actual position is determined by this option’s setting plus the settings for the AUTOALIGN= or HALIGN= and VALIGN= options.
OPAQUE= boolean
specifies whether the layout background is opaque (TRUE) or transparent (FALSE).
Default: FALSE
Interaction: When this option is set to FALSE, the background color is not used.
ORDER=ROWMAJOR | COLUMNMAJOR
specifies whether cells are populated using column priority or by row priority.
Default: ROWMAJOR
ROWMAJOR
fills all the columns in a row, from left to right, before going to the next row.
COLUMNMAJOR
fills all the rows in a column, from top to bottom, before going to the next column.
Requirement: When this option is set to COLUMNMAJOR, the ROWS= option must be specified to indicate how many rows to fill before wrapping to the next column. The default number of rows is 1.
Requirement: When this option is set to ROWMAJOR, the COLUMNS= option must be specified to indicate how many columns to fill before wrapping to the next row. The default number of columns is 1.
Interaction: The ROWS= option is ignored when ORDER=ROWMAJOR. The COLUMNS= option is ignored when ORDER=COLUMNMAJOR.
PAD=dimension | (pad-options)
specifies the amount of extra space that is added inside the layout border.
Default: The default padding for all sides is 0. Values without units are in pixels (px). A unit must be provided if other than pixels.
dimension
Specifies a dimension to use for the extra space at the left, right, top, and bottom of the layout border.
(pad-options)
Enables separate settings for the left, right, top, and bottom padding dimensions. Use the pad-options to create non-uniform padding. These options must be enclosed in parentheses. Each option is specified as a name = value pair. Sides not assigned padding are padded with the default amount.
Values without units are in pixels (px). A unit must be provided if other than pixels.
LEFT=dimension specifies the amount of extra space added to the left side.
RIGHT=dimension specifies the amount of extra space added to the right side.
TOP=dimension specifies the amount of extra space added to the top.
BOTTOM=dimension specifies the amount of extra space added to the bottom.
ROWGUTTER= dimension
specifies the amount of empty space between the rows.
Default: 0
If there are n rows, then there are n-1 gutters.
ROWS=integer
specifies the number of rows in the layout.
Default: If ORDER=COLUMNMAJOR, the default is 1. If ORDER=ROWMAJOR, this option is ignored and as many rows are created as needed to satisfy the COLUMNS= request.
Restriction: Assuming ORDER=COLUMNMAJOR, if ROWS=n and there are m cells defined, and n > m, then only m rows are created (there are n - m cells with zero size).
This option is used to create a grid with a fixed number of rows, without concern for how many columns. For example, the following settings ensure that rows 1 and 2 in the first column are filled with content, as shown in the figure:
layout gridded / rows=2 order=columnmajor border=true ;
  entry '1' /border=true;
  entry '2' /border=true;
  entry '3' /border=true;
endlayout; 
grid with set number of rows
SHRINKFONTS=boolean
specifies whether fonts in the layout are scaled when the size of the output is reduced.
Default: FALSE. Fonts maintain their size regardless of the output size.
VALIGN=CENTER | TOP | BOTTOM | number
specifies this layout’s vertical alignment within its parent when nested within an overlay-type or region layout. For more information about how child positions are determined in an overlay-type or region layout, see the LAYOUT OVERLAY’s Statement Summary.
Default: CENTER
Range: A number specification can range from 0 to 1. The number represents a fraction of the parent container’s height, where 0 is on the bottom and 1 is on the top.
Restriction: This option is available only when this statement is nested within an overlay-type or region layout. It is ignored if this statement is the outermost layout or if the parent layout is not an overlay-type or region layout.
Interaction: For a number setting to take effect, LOCATION=INSIDE must be set. A number setting is invalid on this option when LOCATION=OUTSIDE.
Interaction: If the AUTOALIGN= option is enabled, this option is ignored.