Specifying Colors in SAS/GRAPH Programs

How to Specify Colors

SAS/GRAPH enables you to set colors in several ways. You can do any of the following:
  • specify colors in procedure action statements for any procedures that create graphics output. For example, the CAXIS= option in the HBAR statement specifies a color for the response and midpoint axis lines. These options are described in the documentation for the individual procedures.
  • specify colors in global statements that enhance procedure output: AXIS, FOOTNOTE, LEGEND, PATTERN, SYMBOL, and TITLE. You can also specify colors in the NOTE statement, which is a local statement, not a global statement. See SAS/GRAPH Statements.
  • use options in the GOPTIONS statement that define colors for specific graphics elements. See Specifying Colors in a GOPTIONS Statement.
  • define a color list with the GOPTIONS COLORS= option. See COLORS.
  • specify a different style, modify an existing style, or create a custom style. See Using ODS Styles, Device Parameters, and Options for more information about styles.
  • modify the color list in the device entry for the device that you want to use. However, the colors listed in the device entry are not used unless styles are turned off.See Using a Device's Color List and GDEVICE Procedure for more information.
See Precedence of Appearance Option Specifications for information about which settings take precedence when colors are set in more than one way.

Specifying Colors in a GOPTIONS Statement

The GOPTIONS statement has several graphics options that set colors for specific graphical elements. These colors are used unless they are overridden by more specific options specified on other global statements or on procedure statements.
Option
Purpose
CBACK=
Specifies the color of background for graphics output
CBY=
Specifies the color of BY lines in graphics output
CPATTERN=
Specifies the color of fill patterns
CSYMBOL=
Specifies the color of SYMBOL definitions
CTEXT=
Specifies the color of all text and the border in graphics output
CTITLE=
Specifies the color of border, plus all titles, footnotes, and notes
You can also use the COLORS= option in a GOPTIONS statement to specify a list of colors rather than specific colors for individual graphical elements. Refer to Graphics Options and Device Parameters Dictionary for complete information about each of these graphics options.

Defining and Using a Color List

Introduction to the Device Color Lists

Each device is associated with a list of colors that it can use. This list is defined in the device entry for the device. You can modify this list as needed. However, this device-specific list of colors is not used unless you turn off styles by specifying the NOGSTYLE system option. See Using a Device's Color List.
You can also use the GOPTIONS statement to specify a list of colors for SAS/GRAPH to use instead of the device-specific color list or the colors defined by the current style. Colors specified in the GOPTIONS statement are always used regardless of the setting of the GSTYLE or NOGSTYLE system option. See Building a Color List with the GOPTIONS COLORS= Option for more information.
The color selected from a color list varies depending on the procedure using the color and graphical element that it is drawing. Usually, the first color in the list is used. However, certain procedures can select other colors. For example, if the CAXIS= option is not specified in the GCONTOUR procedure's PLOT statement, the procedure selects the second color from the color list to draw the axes. See the documentation for individual procedures for more information.

Using a Device's Color List

If you specify the NOGSTYLE system option and you do not define a color list with the COLORS= graphics option, then SAS/GRAPH uses the color list from the current device. This color list is found in the device entry of the specified device. The color list might change if you select a different device during a SAS session.
When SAS/GRAPH assigns colors from the current device's color list, this assignment uses some of the colors that you can specify for a graph. The limit on the number of colors that can be used in your output is set by the current device. For example, the PNG device is a true color device and can use up to 16 million different colors. However, the GIF device is limited to 256 colors.
To view, create, or modify a device's color list, use the GDEVICE procedure. See GDEVICE Procedure.
To reset a color list back to the default color list, for the current device driver, specify the COLORS= option without specifying any colors.
goptions colors=;

Building a Color List with the GOPTIONS COLORS= Option

To build a color list, use the COLORS= option in the GOPTIONS statement. A color list specified with the COLORS= option overrides the color list of the current device. Building a color list is useful for selecting a subset of colors in a specific order for graphics output. For example, to ensure that the colors red, green, and blue are available in that order, you can specify any of the following:
goptions colors=(red green blue);
goptions colors=(CXFF0000 CX00FF00 CX0000FF);
goptions colors=(medium_red medium_green medium_blue);
You can specify colors in any color-naming schemes described in Color-Naming Schemes. Each value specified in a color list must be one of the following:
  • a valid color name, not to exceed 64 characters
  • a valid color code, not exceed eight characters
Note: The COLORS= graphics option provides only a default lookup table. Any time you explicitly select any other colors in your SAS/GRAPH program, those colors are used to draw the graphical elements for which you have specified them.
See COLORS for more information.