colorramp | Construct a sequential or diverging color set | colorramp |
The COLORRAMP macro constructs a set of RGB colors ranging from a
starting color to an ending color, optionally going through a middle
color. The result appears as the COLORVAR=
variable in an OUT=
output data set, and optionally as a macro variable named by the
RESULT=
parameter.
The ends and middle of the color scale can be specified either as 6-character RRGGBB hex strings, as 8-character HLS strings (Hhhllss), or as the predefined SAS/Graph color names, e.g., 'very light purple'. Except for RRGGBB, this requires the SAS-supplied COLORMAC macro, available with SAS V8+.
START=
, END=
and MIDDLE=
are each converted to decimal red, green,
blue components, and linear interpolation is performed on each,
from START=
to END=
, possibly through MIDDLE=
. This means that
if you prefer to use HLS colors, the result will not be exactly
linear in HLS space, though the difference will probably be small
unless very few colors are used.
The COLORRAMP macro is defined with keyword parameters. The N=
parameter is required.
The arguments may be listed within parentheses in any order, separated
by commas. For example:
%colorramp(n=10); %colorramp(start=red,mid=very light gray,end=0000FF, n=8, display=Y); %colorramp(start=red, end=blue, n=6, result=mycolors); %put Colors: &mycolors; %colorramp(start=H00080FF, end=H07880FF, n=10, out=mycolors); %genpat(n=nobs, data=mycolors);
START=FF0000
]
START=
color to the MIDDLE=
color, then to the END=
color. When N=
is an even number, you can get a symmetric
set of colors by specifying DUPMID=1
; otherwise, there is
one fewer color in the set from START=
to MID=
than from
MID=
to END=
.
END=0000FF
]
DUPMID=0
]
OUT=
data set.
This is a SAS/Graph RGB color of the form CXrrggbb.
[Default: COLORVAR=COLOR
]
OUT=COLORS
]
DISPLAY=N
]
OUT=
data set.
%include macros(colorramp); *-- or include in an autocall library; %colorramp(start=red, end=blue, n=7, display=Y, out=mycolors); proc print data=mycolors; id color;Produces:
color red green blue rgb nc colornum CXFF0000 255 0 0 FF0000 7 1 CXD5002B 213 0 43 D5002B 7 2 CXAA0055 170 0 85 AA0055 7 3 CX800080 128 0 128 800080 7 4 CX5500AA 85 0 170 5500AA 7 5 CX2B00D5 43 0 213 2B00D5 7 6 CX0000FF 0 0 255 0000FF 7 7