Can you name all the SAS colors?

2

Anybody can come up with a list of simple colors, such as red, green, and blue. If you're a bit more color savvy, you might even throw in indigo, magenta, and fuchsia. But what about more obscure names such as cornsilk, mistyrose, and midnightblue? This blog post will help you visualize and use all 141 of the SAS colors!

Before we get started, let me put you into a colorful mood! Below is a painting from my favorite artist, Sara! I really like the way she uses colors & shapes in her paintings. Note that she's got an art show coming up in Durham, NC on Sept 16, 2016, called Dis-sec-tion of Col-or - if you like her style, you should drop by and see more of her work!

sara_art

 

Now, on to those 141 SAS colors... The term "SAS colors" is a bit vague, so let's get a bit more specific. Let's limit it to the colors that are predefined in the SAS Registry, that you can use by name in SAS/Graph. A table on the SAS support site lists 141 such colors, so we'll go with that list. The support page shows the colors in table form (including the name, the rgb hex code, and the hls color code), sorted by color name, and then sorted by hue. Here are 2 screen captures of portions of their two tables:

sas_colors1

sas_colors2

These tables are fine & useful. You can see all 141 color names. You can use Ctrl+f in your browser to search for pieces of color names (such as 'pink'), and you can copy-n-paste the color names (or rgb or hls codes) from the table. So, we're done, right?...

Well, not quite! :-)

The only thing wrong with this table is I don't think it was created using SAS software! In any event, I wanted to create my own version, using SAS! So I copy-n-pasted all the color names & codes into a text file, read them into a SAS dataset, and used Proc Print to create my own table.

my_color_table1

But my table was missing something - a sample of each color! I put on my thinking cap, and decided to use a technique for adding "traffic light" colors to the background of cells in a table. I would create a user defined format (udf) called colorfmt, such that the value of this format was a color name, and then tell Proc Print to use that color name to color the background of the table cell!

Here's the code I used to generate the udf from the data:

proc sql noprint;
create table foo as
select unique color_swatch as start, rgb_name as label
from color_data;
quit; run;
data control; set foo;
fmtname = 'colorfmt';
type = 'C';
end = START;
run;
proc format lib=work cntlin=control;
run;

And here's how I utilized that udf in my Proc Print:

var color_swatch / style={background=$colorfmt.};

Here's what my table looks like with this addition:

my_color_table2

Having the rgb code printed on top of the color sample is a bit repetitive and distracting, therefore I modified my Proc Print one more time, making the rgb code's text (ie, the foreground) also print using the color format (rather than black), creating the final table.

var color_swatch / style={foreground=$colorfmt. background=$colorfmt.};

my_color_table3

I also sorted the data by hue, and printed the table a second time, and set up an html anchor so you can jump right to the hue table. Now we have a really nice table of the SAS colors, created by SAS - how meta is that!?! :-)

my_color_table4

Hopefully you will find this table useful for choosing SAS colors by simple/meaningful names. I also hope you will find many other uses for the Proc Print tricks I demonstrated in my code!

And while you're in a colorful mood, I'll leave you with a few more of Sara's colorful paintings (a 6'2"x3' orange one, a 3'8"x5' blue one, and then one I had her make especially for my office) ...

sara_orange

sara_blue

office_with_sara_painting

Share

About Author

Robert Allison

The Graph Guy!

Robert has worked at SAS for over a quarter century, and his specialty is customizing graphs and maps - adding those little extra touches that help them answer your questions at a glance. His educational background is in Computer Science, and he holds a BS, MS, and PhD from NC State University.

Related Posts

2 Comments

Back to Top