Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

50 Shades of Grey

If your sensibilities were offended by a book with this title fear not, what follows is a demonstration of requesting any shade of grey on a graph.

Actually in SAS we are not limited to 50, we can easily request any of 256 shades of grey, however to be brutally honest we thought this SAS tip title would generate more attention.

SAS supports numerous naming conventions for specifying colours, namely RGB, RGBA, CYMK, HLS (Tektronix Colour Standard), HSV/HSB, Gray Scale, SAS Colour Names or the interesting Colour Naming System (CNS) where you can specify colours with names such as "Medium Greyish Yellow" directly in the color= parameter in your program.

In this example, using the Gray scale naming convention is of interest (noting that SAS accepts the English spelling in addition to the documented American English).

The colour name is suffixed with a lightness shade specified in hexadecimal, from 00 through to FF, therefore allowing up to 256 shades. The following data step creates 50 records in a data set to be used as an attributes map in Proc SGPLOT, each with a differing shade of grey:

data shades;
  retain id "grey_id";
  do value = 1 to 50;

The HEX format is used to specify a two digit hex number and that we incremented the number in steps of five to get a roughly even selection of greys.

Next we created a sample data set and associated our attribute map with these data in the SGPLOT. We used a VBAR statement and some options to restrict the use of axes and legends:

data sample_data;
  do xvar = 1 to 50;
proc sgplot data=sample_data dattrmap=shades; yaxis display = none; xaxis display = none; keylegend / across=0; vbar xvar / response = yvar group=gvar groupdisplay=cluster attrid=grey_id ; run;

The resulting chart is shown below.

50 Shades of Grey

There are industries who use SAS where monochrome colours remain a requirement. This tip illustrates uses of greyscale colours with modern SAS programming techniques.