brewerpal Generate Brewer color palette(s) brewerpal

SAS Macro Programs: brewerpal

$Version: 1.1 (22 Nov 2005)
Michael Friendly
York University

The brewerpal macro ( [download] get

Generate Brewer color palette(s)

The BREWERPAL macro generates a set of SAS/Graph colors for one of the color palettes developed by Cynthia Brewer. These include color scales for sequential (quantitative) variables, discrete (qualitative) variables, and bipolar (diverging) variables, with varying numbers of levels. The intended use is for constructing sets of color values with SAS/Graph, such as in SYMBOL and PATTERN statements.

See: Color Brewer for an online application demonstrating these color scales. See brewer.all for an image with maximal number of colors for each scale.

The result is returned in an output data set with a COLOR variable (RGB color code). Optionally, the list of all colors may be saved to a macro variable as a blank-separated list.


The BREWERPAL macro is modeled on the RColorBrewer R package. See:

It requires that the data set colors.brewer has already been created (by the file You may have to modify the libname statement in the macro, or specify the LIB= parameter for something other than 'colors'.

As implemented here, it simply selects observations from the &lib..brewer data set.


The BREWERPAL macro is defined with keyword parameters. Typically, the N= and PALETTE= arguments are specified. The arguments may be listed within parentheses in any order, separated by commas. For example:

  %brewerpal(n=7, palette=Accent);


Number of different colors included in the palette [Default: N=3]
Palette name. Must be one of the values created in the palnames lists:
BrBG PiYG PRGn PuOr RdBu RdGy RdYlBu RdYlGn Spectral
Accent Dark2 Paired Pastel1 Pastel2 Set1 Set2 Set3
Blues BuGn BuPu GnBu Greens Greys Oranges OrRd PuBu PuBuGn PuRd Purples RdPu Reds YlGn YlGnBu YlOrBr YlOrRd
If PALETTE= is not specified, all palettes are selected.
Library name for the brewer data set [Default: LIB=COLORS]
Palette category: DIV, QUAL or SEQ. If not specified, all palette categories are selected.
Name of the output data set. Contains the variable COLOR, as well as the Red, Green, Blue (decimal) components of each color [Default: OUT=PALETTE]
Name of output macro variable containing color list. If specified, a macro variable of that name is created with a list of all distinct colors in the OUT= data set.


%include macros(brewerpal);        *-- or include in an autocall library;

  *-- Typical usage, for a given palette;
  %brewerpal(n=6, palette=Blues, result=blues6);
  %put blues6 = &blues6;
  title 'Blues palette, n=6 colors';
  proc print;
Printed Output:
  Obs cat palette nc maxc category   paldesc   colnum  color   red green blue

   1   3   Blues   6   9    seq    Blue shades    1   CXEFF3FF 239  243   255
   2   3   Blues   6   9    seq    Blue shades    2   CXC6DBEF 198  219   239
   3   3   Blues   6   9    seq    Blue shades    3   CX9ECAE1 158  202   225
   4   3   Blues   6   9    seq    Blue shades    4   CX6BAED6 107  174   214
   5   3   Blues   6   9    seq    Blue shades    5   CX3182BD  49  130   189
   6   3   Blues   6   9    seq    Blue shades    6   CX08519C   8   81   156
Log Output:
80         %put blues6 = &blues6;
Generate PATTERN statements:
  *-- Generate pattern statements with the blues6 list;
  %genpat(n=6, colors=&blues6);
Other examples:
  %brewerpal(n=9, palette=YlOrRd);
  title 'Yellow-Orange-Red palette, n=9 colors';
  proc print;
  *-- All n=4 palettes for diverging colors;
  %brewerpal(n=4, category=div);
  title 'Diverging palettes, n=4 colors';
  proc print;

See also Create Brewer colors data set
colorramp Construct a sequential or diverging color set
gensym Macro to generate SYMBOL statements