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
Command
Purpose
%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 that 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 about the color value produced by using this macro.
Note: In the PUT statement, %CMYK(cyan, magenta, yellow, black), should not be placed in quotations.
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.
%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 about HLS color values.For more information about valid color-naming scheme color names, see Color Naming System (CNS) Values, or enter the following into the command-line of the Program Editor:
 %HELPCLR(CNS);
Note: The %CNS macro accepts only CNS color names where a space is used to separate the words in the color name.
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.
%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.