More colours with Proc Print and Traffic Light Analysis
Monday, March 31, 2008
Jared in SAS

For work we do a "traffic light" analysis. Basically one assigns a red, yellow or green  score (i.e. fail, barely pass, pass) to attributes. In my case, we assign the colour to a customers satisfaction towards an attributed of our product.

My problem was that I was doing my colourizing in MS Word which was my ODS output. What I need is to automate cell colours depending on the values.

I went and created the following test code, but I ran into a problem with colours:

 data tempdata;
    length Q1 $15;
    input Site Q1 $ evaltot_Sum Red Amber Green;
    cards;
    3 Cleanliness 2 4 2 4
    3 Friendliness 3 4 4 3
    3 Responsiveness 3 4 4 3
    3 Condition 3 4 4 3
    3 Safety 3 4 4 3
    4 Cleanliness 1 1 4 4
    4 Friendliness 3 4 4 3
    4 Responsiveness 3 4 4 3
    4 Condition 3 4 4 3
    4 Safety 3 4 4 3
    9 Cleanliness 2 4 2 4
    9 Friendliness 3 4 4 3
    9 Responsiveness 3 4 4 3
    9 Condition 3 4 4 3
    9 Safety 1 1 4 4
    ;
    run;

    proc format;
    picture bgcolor 3 = ‘Green’
    2 = ‘Yellow’
    1 = ‘Red’
    4 = ‘Gray’;
    run;

    ods html;
    proc print data = tempdata noobs label;
    var Q1;
    var Red / style={background=bgcolor.};
    var Amber / style={background=bgcolor.};
    var Green / style={background=bgcolor.};
    by Site;
    label Red=’R’ Amber=’A’ Green=’G’ Q1=’Services and Facilities’;
    run;
    ods html close;

Let’s say I wanted to use a darker yellow/orange colour such as Amber (which is the actual colour used in traffic lights by the way). If I type in ‘Amber’, it won’t work. What other colours are available to use?

I posed this question to the SAS Google Group, and asked how I could use more colours in my proc format.

The following resource were sent:

The last resource was the best at showing me which colours I could use. However, with my sample code, I could only use the Color Name (predefined SAS colors) and not HLS or RGB .

But then another response came in which allowed me to use RGB:

Proc Format ;
Value BGColor
1 = CXFF0000
2 = CXFFFF00
3 = CX00FF00
4 = CXD3D3D3
5 = CXA69F7A ;
Run ;

The difference seems to be VALUE v.s. PICTURE formats. Now I can use any colour I wantWorks like a charm though.

 

Article originally appeared on jaredprins (http://jaredprins.squarespace.com/).
See website for complete article licensing information.