SAS Institute. The Power to Know

SAS/GRAPH(R) 9.2 Reference

Previous Page | Next Page

SAS/GRAPH Colors and Images

Specifying Colors in SAS/GRAPH Programs

SAS/GRAPH software enables you to set colors in:

These specifications, alone or in combination, give SAS/GRAPH software the colors it needs to generate graphics output. Colors can be specified using color names, such as RED, or color codes, such as CXFF0000. Color names must not exceed 64 characters. Color codes must not exceed eight characters. All color values must be in a valid SAS color-naming scheme (see Color-Naming Schemes).


Precedence of Color Specifications

SAS/GRAPH software uses the first color it finds in the following list:

  1. colors specified with the procedure statement options

  2. colors specified in global statements such as the AXIS, PATTERN, LEGEND, and SYMBOL statements

  3. color options in the GOPTIONS statement that control specific graph elements such as the background color or title text color. See Specifying Colors in a GOPTIONS Statement.

  4. the COLOR list (COLORS= option) in the GOPTIONS statement

  5. the colors specified by the current style (if GSTYLE is in effect) or the color list in the current device driver (if NOGSTYLE is in effect).


Specifying Colors in a GOPTIONS Statement

The GOPTIONS statement has several graphics options that specify colors for graphics elements. These colors are used unless they are overridden by more specific options specified on other global statements or on procedure statements. (See Precedence of Color Specifications.)

Option Sets the color for
CBACK= background for graphics output
CBY= BY lines in graphics output
CPATTERN= PATTERN statements
CSYMBOL= SYMBOL statements
CTEXT= all text and the border in graphics output
CTITLE= border, plus all titles, footnotes, and notes

Refer to Graphics Options and Device Parameters Dictionary for complete information about each of these graphics options.


Defining and Using a Color List

If SAS/GRAPH software does not find a color specification on a procedure or global statement, and a color for the graphic element is not specified in the GOPTIONS statement, then SAS/GRAPH software uses colors from the following sources:

  1. the COLORS= option on a GOPTIONS statement

  2. the color specified by the current style or, if the NOGSTYLE option is specified, the color list of the current device driver.

The color selected from the color list varies depending on the procedure using the color, and graphics element it's 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 an individual procedure for more information.


Building a Color List

To build a color list, use the COLORS= option on the GOPTIONS statement. This specified color list overrides the color list of the current device driver. 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:

goptions colors=(red green blue);

Each value you specify in a color list must be either a valid color name or a valid color code. Color names must not exceed 64 characters, and color codes must not exceed eight characters. For an explanation of SAS color names and codes, see Color-Naming Schemes.

SAS provides, in the SAS Registry, a set of ordinary-language color names that you can use for colors that are common to most Web browsers. For a list of these names, showing both the ordinary-language name, and its associated RGB value, you can run the following code and view the output in the Log window:

proc registry list
 startat="COLORNAMES";
run;

You can also modify entries in this list and add your own names, and their associated RGB values. For more information on viewing and modifying the list of color names, see .

Note:   The COLORS= graphics option provides only a default lookup table. Any time you explicitly select any other colors in your SAS/GRAPH software program, those colors are used to draw the graphics elements for which you have specified them.  [cautionend]

For a pen plotter, SAS/GRAPH software uses the order of the colors in the COLORS= graphics option to define the order of pens for a multiple pen plotter, or to make a pen plotter prompt you to change the pen when a graph uses more colors than the plotter has loaded.


Using a Device's Default Color List

If you do not define a color list with the COLORS= graphics option, and if you specify the NOGSTYLE option, then SAS/GRAPH software uses the color list from the current device driver. This color list is found in the device entry of the specified device driver (for details on specifying a device driver, refer to The GOPTIONS Procedure). The color list changes if you select a different device driver during a SAS sessio, and have not specified the COLORS= graphics option.

To view and modify the device's default color list, use the GDEVICE procedure (for details, refer to The GDEVICE Procedure).


Overriding the Default Color List

If you do not specify colors for certain graphics elements or do not specify a color list with the COLORS= graphics option, then the SAS/GRAPH software procedures assign colors from the color list of the current device driver. In some procedures, this assignment takes up some of the 256 colors that you can specify for a graph. For example, if no colors are specified, the G3D procedure uses the first three colors from the color list to draw the text, the plot axes, and the plot symbols. These colors take up three of the 256 colors that you can specify for the graph. Therefore, you can specify 253 additional colors for your graph before a warning is issued, and the colors are remapped.

To use only the colors that you explicitly specify in your SAS program, submit

goptions colors=(none);

The colors from any elements that have a color explicitly specified in your SAS program are combined to form a color list. This color list is used to assign colors to the elements that do not have a color explicitly specified. If no colors are explicitly specified, black is used. This setting is useful if you want to generate graphics output with the maximum of 256 colors, and you do not want to use any of the default colors from the current device driver.


Resetting the Color List to the Default

To reset a color list back to the default color list, for the current device driver, specify

goptions colors=();


Color-Naming Schemes

The valid color-naming schemes are

For the CMYK color scheme, color specifications must be enclosed in quotation marks. For the SAS color names and CNS names, quotation marks are required, if the color name contains spaces. In all other instances, quotation marks are optional.

You can freely intermix colors using different color-naming schemes in your programs. However, depending on your device capabilities, the color that is displayed might not be the color that you expect. See Colors and Device Capabilities for information on how to tell if your device supports user-defined colors.

Note:   The colors shown in the output in the SAS Help and Documentation might be different from the colors you see on your device.  [cautionend]


Selecting a Color-Naming Scheme

Each of the color-naming schemes supported by SAS/GRAPH software offer their own set of advantages and disadvantages based on the implementation of the color-naming scheme and the desired color. RGB and CMYK are older hardware-oriented color-naming schemes. Creating specific RGB or CMYK colors might be less intuitive than creating colors using the user-oriented color-naming schemes: HLS, HSV, gray scale, SAS named colors, or CNS colors. For both hardware-oriented and user-oriented color-naming schemes, the color utility macros allow you to create colors for a specific color-naming scheme and convert color values between color-naming schemes (see Using the Color Utility Macros for more information).


Hardware-Oriented Color-Naming Schemes Overview

The RGB color-naming scheme is usually used to define colors for a display screen. This color-naming scheme is based on the properties of light. With this color system, a color is defined by its red, green, and blue components. Individual amounts of each color are added together to create the desired result. All the colors combined together create white, and the absence of all color is black.

CMYK is a special color-naming scheme used in four-color printing. Whereas the RGB scheme is based on the principles of light, the CMYK scheme is based on the principles of objects reflecting light. Cyan, magenta, and yellow absorb red, green, and blue light, respectively. When cyan is set at maximum, for example, all the red light is absorbed. Combining equal values of cyan, magenta, and yellow produces black, but this color can appear brown when printed. Therefore, the black component (K) of CMYK can be used to specify the level of blackness in the output. A lack of all colors produces white when the output is printed on white paper.


RGB Color Codes

You can use the RGB color-naming scheme to specify a color in terms of its red, green, and blue components. Color names are of the form CXrrggbb, where

  • CX indicates that this is an RGB color specification

  • rr is the red component

  • gg is the green component

  • bb is the blue component.

The components are given as hexadecimal numbers in the range 00 through FF (0% to 100%), where lower values are darker, and higher values are lighter. This allows for up to 256 levels of each color component (over 16 million different colors). For example, bright red is specified as CXFF0000, white as CXFFFFFF, black as CX000000, and green as CX00FF00.

Any combination of the color components is valid. Some combinations match the color produced by predefined SAS color names. See for information on viewing the RGB combinations that match predefined SAS color names.

Note:   When printed, RGB color values are automatically converted to the CMYK color values so that the colors display appropriately in the output.  [cautionend]


CMYK Color Codes

To specify the colors from a printer's Pantone Color Look-Up Table, you can use the CMYK color-naming scheme to specify colors in terms of their cyan, magenta, yellow, and black components. Color names are of the form 'ccmmyykk', where

  • cc is the cyan component

  • mm is the magenta component

  • yy is the yellow component

  • kk is the black component.

The components are given as quoted hexadecimal numbers in the range 00 through FF, where higher values are darker and lower values are lighter. This scheme allows for up to 256 levels of each color component. For example, red is specified as '00FFFF00', green as 'FF00FF00', process black (using cyan, magenta, and yellow ink) as 'FFFFFF00', and pure black (using only black ink) as '000000FF'. For CMYK color specifications, the quotes are required.

CMYK color specifications should be used only for devices that support four colors. If a CMYK color is used on a three-color device, the device processes the color specification, but the resulting colors might not be appealing. Moreover, different CMYK colors might map to the same device color because a four-color space supports more colors than a three-color space.

Note:   You can specify a CMY value by making the kk, the color's black component, zero (00).  [cautionend]


User-Oriented Color-Naming Schemes Overview

The HLS color-naming scheme follows the Tektronix Color Standard. To make the HLS color model consistent with the HSV coordinate system, Tektronix places blue at zero degrees. With the HLS color naming-scheme you specify the hue, lightness, and saturation levels.

With the HSV color-naming scheme, you specify the hue, saturation, and value (brightness) levels.

The gray scale color-naming scheme allows you to specify the lightness or darkness of gray using the word GRAY and a lightness value.

A predefined list of the SAS color names, and their accompanying RGB values are contained in the SAS Registry Editor. The SAS Registry Editor also allows you to add your own SAS color names. With these colors, you can specify the name itself or the RGB value associated with that color name.

With CNS, you develop your color value by selecting and combining valid lightness, saturation, and hue terms. The CNS colors are based on the HLS color model, and display fairly uniform transitions between color values.

Note:   The next valid color value on the foreground color list replaces invalid colors. Messages are written to the SAS log detailing the colors substituted for invalid color values.  [cautionend]


HLS Color Codes

You can use the HLS color-naming scheme to specify colors in terms of hue, lightness, and saturation components. SAS/GRAPH software uses an HLS color scheme that is modeled directly after the Tektronix Color Standard. HLS color names are of the form Hhhhllss, where

  • H indicates that this is an HLS color specification

  • hhh is the hue component

  • ll is the lightness component

  • ss is the saturation component.

The components are given as hexadecimal numbers. The hue component has the range of 000 through 168 hexadecimal (168 hexadecimal is equivalent to 360 decimal). Both the lightness and saturation components are hexadecimal and scaled to a range of 0 to 255 expressed with values of 00 through FF (0% to 100%). Thus, they provide 256 levels for each component. For example, blue is specified as H00080FF and light gray as H000BB00. When the saturation is set to 00, the color is a shade of gray that is determined by the lightness value. Therefore, white is defined as HxxxFF00 and black as Hxxx0000, where xxx can be any hue.

Tektronix Color Standard

[Tektronix Color Standard]


HSV (or HSB) Color Codes

You can use the HSV color-naming scheme to specify colors in terms of hue, saturation, and value (or brightness) components. HSV color names are of the form Vhhhssvv, where

  • V indicates that this is an HSV color specification

  • hhh is the hue component

  • ss is the saturation component

  • vv is the value, or brightness component.

The components are given as hexadecimal numbers. The hue component has the range of 000 through 168 hexadecimal (168 hexadecimal is equivalent to 360 decimal). Both the saturation and value (brightness) components are hexadecimal and scaled to a range of 0 to 255 expressed with values of 00 through FF (when the saturation is set to 00, the color is a shade of gray determined by the value). Thus, they provide 256 levels for each component.

For example, blue is specified as V0F0FFFF, light gray as Vxxx00BB, and white as Vxxx00FF, where xxx can be any hue. For white and black, the value component determines the intensity of gray level.


Gray-Scale Color Codes

Gray-scale color names are of the form GRAYll. The value ll is the lightness of the gray, and is given as a hexadecimal number in the range 00 through FF. This scheme allows for 256 levels on the gray scale. For example, GRAYFF is white, GRAY00 is black, and GRAY4C is a dark gray.


SAS Color Names and RGB Values

The SAS Registry Editor contains valid color names and RGB values. The predefined color names and RGB values in the SAS Registry are common to most web browsers. In addition to viewing predefined SAS color names and RGB values, the SAS Registry Editor also allows you to create and define your own color names and RGB values. See for more information.

Note:   Hardware characteristics might cause some colors with different color definitions to appear the same. Also, the same predefined color is likely to appear different on different devices, and might not appear correctly on some devices.  [cautionend]


CNS Color Names

You can specify a CNS color value's lightness, saturation, and hue using the following terms:

Lightness Saturation Hue
Black Gray Blue
Very Dark Grayish Purple
Dark Moderate Red
Medium Strong Orange/Brown
Light Vivid Yellow
Very Light
Green
White

CNS values should be written in the following order: lightness saturation hue.

  • color names can be written without space separators between words

  • with an underscore to separate words

  • with a space to separate words, enclosed in quotation marks

The following list contains examples of valid color names:

verylightmoderatepurplishblue

very_light_moderate_purplish_blue

"very light moderate purplish blue"

Note:   The %CNS macro accepts only CNS color names where a space is used to separate the words in the color name. See %CNS (colorname); for more information  [cautionend]

If a CNS color name is also a color name in the SAS Registry, the SAS Registry color value takes precedence. Some CNS color names, and color names in the SAS Registry have different color values. To use a CNS color value when the color name is also in the SAS Registry, place quotes around the color name.

  • the lightness values black and white should not be used with saturation or hue values

  • medium is the default lightness value, unless otherwise specified

  • vivid is the default saturation value, unless otherwise specified

  • gray is the only saturation value that can be used without a hue

  • at least one hue must be used unless the CNS value is black, white, or some form of gray

One or two hue values can be used in the CNS color name. When using two hue values, the hues must be adjacent to form a color. The hues are located in the following circular order: blue, purple, red, orange/brown, yellow, green, and then returning to blue. When two hues are used, the resulting color is a combination of both colors.

Use the suffix -ish to reduce the effect of a hue when two hues are combined. For example, reddish purple is less red than red purple. If you are using a color with an -ish suffix, this color must precede the color without the -ish suffix.


Using the Color Utility Macros

The %COLORMAC macro contains several sub-component macros that can be used to construct and convert color values for the different color-naming schemes supported by SAS. The %HELPCLR macro provides information about the %COLORMAC sub-component macros. The following table shows information that will appear in your SAS log when you call the %HELPCLR macro from the command-line:

Using the %HELPCLR macro