Previous Page | Next Page

SAS/GRAPH Colors and Images

Specifying Colors in SAS/GRAPH Programs

SAS/GRAPH enables you to set colors in several ways. You can do any of the following:

See Precedence of Appearance Option Specifications for information on 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 Sets the color for
CBACK= background for graphics output
CBY= BY lines in graphics output
CPATTERN= fill patterns
CSYMBOL= SYMBOL definitions
CTEXT= all text and the border in graphics output
CTITLE= 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 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 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 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 The 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 . Each value specified in a color list must be one of the following:

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

See COLORS for more information.


Color-Naming Schemes


Introduction to Color-Naming Schemes

The valid color-naming schemes are as follows:

Examples of Specifying Colors shows examples of each color-naming scheme.
Examples of Specifying Colors
Color-Naming Scheme Example
RGB
COLORS=(cx98FB98 cxDDA0DD cxFFDAB9 cxDB7093 cxB0E0E6)
CMYK
COLORS=("FF00FF00" "00FFFF00" "FFFFFF00")
HLS
COLORS=(H14055FF H0F060FF H0B485FF H07880FF)
HSV
COLORS=(V0F055FF v010FFFF v03BFFFF v12C55E8)
Gray Scale
COLORS=(GRAY4F GRAY6D GRAY8A GRAYC3)
SAS Registry Colors
COLORS=(palegreen plum peachpuff palevioletred powderblue)
CNS Color Names
COLORS=("very light purplish blue" 
"light vivid green" "medium strong yellow" 
"dark grayish green")

You can also mix color-naming schemes in the same statement, for example:

 goptions colors=(cxEE0044 "vivid blue" darkgreen);

Note:   Hardware characteristics of your output device might cause some colors with different color definitions to appear the same. The same color is likely to appear different on different devices and might not appear correctly on some devices. To determine whether your device supports a specific color-naming scheme, refer to your graphics device documentation.  [cautionend]

Each of the color-naming schemes supported by SAS/GRAPH has its advantages and disadvantages based on how the output is used. For example, if you are creating a report that will be viewed online only, then specifying colors using the RGB naming scheme or the SAS color names defined in the registry might produce better results. If you are creating a report for publishing in printed form, you might want to use the CMYK color-naming scheme.

The color utility macros enable you to create colors for a specific color-naming scheme. These macros convert color values between color-naming schemes. See Using the Color Utility Macros.

Note:   Invalid color names, such as a misspelled color name, are mapped to gray, and a NOTE is issued to the SAS log. A valid color name that is not supported by the current device is mapped to the closest color that is supported by the device.  [cautionend]


RGB Color Codes

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 RGB color codes, a color is defined by its red, green, and blue components. Individual amounts of each color are added together to create the desired color. All the colors combined together create white. The absence of all color creates black.

Color names are in the form CXrrggbb, where the following is true:

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 scheme allows for up to 256 levels of each color component (over 16 million different colors).

Examples of RGB Color Values
Color RGB Value
red CXFF0000
green CX00FF00
blue CX0000FF
white CXFFFFFF
black CX000000

Any combination of the color components is valid. Some combinations match the colors produced by predefined SAS color names. See Using the SAS Registry to Control Color in SAS Language Reference: Concepts for information on viewing the RGB combinations that match predefined SAS color names.


CMYK Color Codes

CMYK is a color-naming scheme used in four-color printing. CMYK is based on the principles of objects reflecting light. Combining equal values of cyan, magenta, and yellow produces process black, which might not appear as pure black. 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.

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

The components are given as hexadecimal numbers in the range 00 through FF, where higher values are darker and lower values are brighter. This scheme allows for up to 256 levels of each color component. Quotation marks are required when the color value starts with a number instead of a letter.

Examples of CMYK Color Values
Color CMYK Value
red 00FFFF00
green FF00FF00
blue FFFF0000
white 00000000
process black (using cyan, magenta, and yellow ink) FFFFFF00
pure black (using only black ink) 000000FF

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

CMYK color specifications are for devices that support four colors. If a CMYK color is used on a three-color device, the device processes the color specification. The resulting colors might not be as expected. Different CMYK colors might map to the same device color because a four-color space supports more colors than a three-color space.


HLS Color Codes

The HLS color-naming scheme follows the Tektronix Color Standard illustrated in 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 colors in terms of hue, lightness, and saturation levels. HLS color names are of the form Hhhhllss, where the following is true:

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.

Examples of HLS Color Codes
Color HLS Color Code
red H07880FF
green H0F080FF
blue H00080FF
light gray H000BB00
white* HxxxFF00, such as H000FF00
black* Hxxx0000 such as H0000000
* 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

Specify the HSV color-naming scheme in terms of hue, saturation, and value (or brightness) components. HSV color names are of the form Vhhhssvv, where the following is true:

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, scaled to a range of 0 to 255, and expressed with values of 00 through FF. Thus, they provide 256 levels for each component.

Examples of HSV (or HSB) Color Codes
Color HSV Color Code
red V000FFFF
green V078FFFF
blue V0F0FFFF
light gray* Vxxx00BB such as V07900BB
white* Vxxx00FF such as V07900FF
black* Vxxx00000 such as V0790000
* When the saturation is set to 00, the color is a shade of gray. The value component determines the intensity of gray level. The xxx can be any hue.


Gray-Scale Color Codes

Specify the lightness or darkness of gray using the word GRAY and a lightness value. Gray-scale color codes 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.

Note:   GRAY, without a lightness value, is a SAS color name defined in the SAS registry (see SAS Color Names and RGB Values in the SAS Registry). Its value is CX808080. Invalid color specifications are mapped to GRAY.  [cautionend]

Examples of Gray-Scale Color Codes
Color Gray-Scale Color Codes RGB equivalent
white GRAYFF CXFFFFFF
light gray GRAYC0 CXC0C0C0
dark gray GRAY40 CX404040
black GRAY00 CX000000


SAS Color Names and RGB Values in the SAS Registry

SAS provides, in the SAS Registry, a set of color names and RGB values that you can use to specify colors. These color names and RGB values are common to most Web browsers. You can specify the name itself or the RGB value associated with that color name. To view the color names as associated RGB values that are defined in the registry, submit the following code;

proc registry list
 startat="COLORNAMES";
run;

SAS prints the output in the SAS log.

You can also create your own color values by adding them to the registry. For more information on viewing and modifying the list of color names, see Using the SAS Registry to Control Color in SAS Language Reference: Concepts.


Color Naming System Values

With CNS, you specify a color value by specifying lightness, saturation, and hue, in that order, using the terms shown in the following table.

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

Follow these rules when you are determining the CNS color name:

One or two hue values can be used in the CNS color name. When using two hue values, the hues must be adjacent to each other in the following list: 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. 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.

Color names can be written in the following ways:

For example, the following are all valid color specifications:

Note:   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, do the following:

  [cautionend]

Using the Color Utility Macros

The color utility macros enable you to define colors for a specific color-naming scheme and convert color values between color-naming schemes.

The %COLORMAC macro contains several subcomponent 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 subcomponent macros. The following table shows information displayed in your SAS log when you call the %HELPCLR macro from the command line.

Using the %HELPCLR macro
Use... To...
%HELPCLR; List the color utility macro names with help information.
%HELPCLR(ALL); Display the short descriptions and examples for each of the color utility macros.
%HELPCLR(macroname); Obtain a short description and an example of a specific color utilities macro. Replace macroname with the name of the color utility macro you are interested in.

When the color utility macros are invoked, the calculated color value is directed to the SAS log. The calculated color can also be used to perform in-place substitutions in the code.

%CMY(cyan, magenta, yellow);
Description Usage Example
Replace cyan, magenta, yellow with numeric values to create an RGB color value. The numeric values that are used in place of cyan, magenta, yellow indicate the percentage of each color to be included in the RGB value. Entering the following code into your Program Editor:
%COLORMAC;
data _null_;
put "%CMY(100,0,100)";
run;

Returns the RGB value CX00FF00 which is green.

%CMYK(cyan, magenta, yellow, black);
Description Usage Example
Replace cyan, magenta, yellow, black with numeric values to create a CMYK color value. The numeric values that are used in place of cyan, magenta, yellow, black indicate the percentage of each color to include in the CMYK color value. See CMYK Color Codes for more information on the color value produced by using this macro. Entering the following code into your Program Editor:
%COLORMAC;
data _null_;
put %CMYK(0,46,16,31);
run;

Returns the CMYK value 0075294F which is purple.

Note:   In the PUT statement, %CMYK(cyan, magenta, yellow, black), should not be placed in quotations.  [cautionend]

%CNS (colorname);
Description Usage Example
Replace colorname with a color-naming scheme color name to create an HLS color value. See HLS Color Codes for more information on HLS color values. For more information on valid color-naming scheme color names see Color Naming System Values or enter the following into the command-line of the Program Editor:

 %HELPCLR(CNS);
Entering the following code into your Program Editor:

%COLORMAC;
data _null_;
put "%CNS(GRAYISH REDDISH PURPLE)";
run;

Returns the HLS value H04B8040 which is grayish reddish purple.

Note:   The %CNS macro accepts only CNS color names where a space is used to separate the words in the color name.  [cautionend]

%HLS(hue, lightness, saturation);
Description Usage Example
Replace hue, lightness, saturation with numeric values to create an HLS color value. Hue should be replaced with any value from 0 to 360. Lightness and saturation indicate a percentage to be included in the HLS color values. See HLS Color Codes for more information. Entering the following code into your Program Editor:

%COLORMAC;
data _null_;
put "%HLS(0,50,100)";
run;

Returns the HLS value H00080FF which is blue.

%HSV(hue, saturation, value);
Description Usage Example
Replace hue, saturation, value with numeric values to create an HLS value from HSV components. Hue should be replaced with any value from 0 to 360. Saturation and value (brightness) indicate a percentage to be included in the HLS color value. See HSV (or HSB) Color Codes and HLS Color Codes for more information. Entering the following code into your Program Editor:

%COLORMAC;
data _null_;
put "%HSV(0,100,75)";
run;

Returns the HSV value V000FFBF which is dark red.

%RGB(red, green, blue);
Description Usage Example
Replace red, green, blue with numeric values to create an RGB color value from RGB color components. The numeric values that are used in place of red, green, blue indicate the percentage of each color to be included in the RGB color value. See RGB Color Codes for more information. Entering the following code into your Program Editor:

%COLORMAC;
data _null_;
put "%RGB(100,100,0)";
run;

Returns the RGB value CXFFFF00 which is yellow.

%HLS2RGB(hls);
Description Usage Example
Replace hls with an HLS color value to create an RGB color value. See HLS Color Codes and RGB Color Codes for more information. Entering the following code into your Program Editor:

%COLORMAC;
data _null_;
put "%HLS2RGB(H04B8040)";
run;

Returns the RGB value CX9F5F8F which is grayish reddish purple.

%RGB2HLS(rgb);
Description Usage Example
Replace rgb with an RGB color value to create an HLS color value. See RGB Color Codes and HLS Color Codes for more information. Entering the following code into your Program Editor:

%COLORMAC;
data _null_;
put "%RGB2HLS(CX9F5F8F)";
run;

Returns the HLS value H04C7F40 which is grayish reddish purple.

Note:   Round-trip conversions using the HLS2RGB and RGB2HLS macros might produce ultimate output values that differ from the initial input values. For example, converting CXABCDEF (a light blue) using %RGB2HLS produces H14ACDAD. Converting this value back to RGB using %HLS2RGB returns CXAACCEE. While not identical, the colors are very similar on the display, and when printed.  [cautionend]

For additional information on color-naming schemes. See Effective Color Displays: Theory and Practice by David Travis and Computer Graphics: Principles and Practice by Foley, van Dam, Feiner, and Hughes.


Processing Limitations For Colors

Using colors in SAS/GRAPH is limited by the number of colors that you can use in one graph and by the capabilities of your device.


Maximum Number of Colors Displayed on a Device

The number of colors that you can display is limited by the graphics output device. If you create a graph with more colors than the device can display, the colors are mapped to an existing color for display. You might also receive a note in the SAS log telling you when a color is mapped to another color, along with the name of the replacement color.

If your device can support 16 million colors, it might not let you use all of them at once. The MAXCOLORS device parameter tells SAS/GRAPH the maximum number of colors it can display simultaneously. MAXCOLORS is the number of foreground colors plus the background color. If you use more than the number of colors set by the MAXCOLORS device parameter, the excess colors are remapped.

Note:   The MAXCOLORS device parameter defaults to the number of colors that the basic model of each graphics device supported can display. If your graphics device can display more colors than the base model, use the PENMOUNTS= graphics option to specify the number of colors your graphics device can display. You can also use the GDEVICE procedure to modify the value of the MAXCOLORS device parameter.  [cautionend]


Replaying Graphs on a Device That Displays Fewer Colors

You can use the GREPLAY procedure to display previously created graphs. Sometimes you might need to replay the graphs on a device that cannot display as many colors as the device on which the graph was originally developed. Use the CMAP statement (see CMAP) to control some of the remapping.

When you replay graphs on devices that display fewer colors than are in the graph, two situations can cause problems:

If you specify colors on a device that does not support the colors requested, the colors are remapped to gray. A note is issued to the SAS log telling you when a color is mapped gray.

The number of colors that your device can display affects the actual colors displayed. If your graphics output device can create a maximum of 64 distinct colors, and your graph contains 256 colors, then the 65th through the 256th color specifications are remapped to the colors specified in the current style. If the NOGSTYLE system option is in effect, the colors are remapped to the device's available colors and might not display as the color you specify.

You can use the TARGETDEVICE= graphics option to preview the way a graph is going to look on a different device. Set the device entry name of the device driver to this graphics option. The graph is displayed as close as possible to the display when the other device is used.

Note:   When you use the TARGETDEVICE= graphics option, SAS/GRAPH uses the color list of the target device as the default color list; any color that you explicitly use is displayed when you preview the graph, although the color might be mapped by the target device. Refer to TARGETDEVICE for complete information about the TARGETDEVICE= graphics option.  [cautionend]

Previous Page | Next Page | Top of Page