Help using Base SAS procedures

Output in Colors

Reply
Regular Contributor
Posts: 229

Output in Colors

Hi iam having a dataset the observations should show in differnt colors based on obs

1-50=Red
51-65=Blue
80-100=Green

data clr;
input age ;
cards
1
25
99
54
23
3
62
100
run;
Super Contributor
Posts: 291

Re: Output in Colors

Here are some basics to make it happen. A format is applied to the foreground to provide the colour scheme that you are looking for. I've shown a pdf output, but you could use ods to send it to html, rtf ...
From a data visualization perspective, it's not a good idea to use red and green together. People who are colour deficient (about 8 - 10% of the population) cannot distinguish the difference between red and green. I suggest that you find a different combination of colours.
Hope this helps.

proc format;
value clr
1-50='Red'
51-65='Blue'
80-100='Green'
;
run;

data clr;
input age ;
cards;
1
25
99
54
23
3
62
100
;
run;


ods pdf file="c:\temp\test.pdf";

proc print data=clr;
var age/style=[foreground=clr.];
run;

ods pdf close;
SAS Super FREQ
Posts: 8,743

Re: Output in Colors

Hi:
When a dataset is stored internally, there are no colors or fonts stored with the data values. However, when you produce a REPORT (such as with one of the SAS procedures or with PROC SQL or a DATA step program) based on your data, you can apply style characteristics to different pieces of the report. When you conditionally change some style characteristic on a REPORT, based on REPORT cell values (either those that come from the data, those that are calculated by a procedure or those that come from summarizing the data) this is called "trafficlighting".

In this case, the procedure/method you are using for your report will determine how the trafficlighting style will be accomplished:
1) If you are using PROC PRINT, PROC REPORT or PROC TABULATE, you can use STYLE= override syntax in the procedure code itself to achieve trafficlighting (PROC REPORT has 2 ways to accomplish trafficlighting, while PROC PRINT and PROC TABULATE only have 1 way to accomplish trafficlighting)
--page 7-8 of this paper show how to achieve trafficlighting with PROC REPORT:
http://support.sas.com/resources/papers/proceedings09/273-2009.pdf (the paper shows the user-defined format method and the CALL DEFINE method for trafficlighting)
--page 6 of this paper has an example of trafficlighting with PROC TABULATE:
http://www2.sas.com/proceedings/forum2007/095-2007.pdf
--page 16-17 of this paper has an example of trafficlighting with PROC PRINT:
http://www2.sas.com/proceedings/sugi30/265-30.pdf

2) If you are using one of the other SAS procedures (PROC MEANS, PROC SQL, PROC ??? or a DATA step program), you use STYLE= or CELLSTYLE syntax in a TABLE template and then link your procedure or DATA step program to the changed TABLE template.
--page 8 in this paper starts with a discussion of trafficlighting in a TABLE template: http://www2.sas.com/proceedings/sugi30/088-30.pdf

In order to understand trafficlighting, however, you also have to understand some of these basic concepts about SAS output and the Output Delivery System:
1) There is no trafficlighting in the LISTING destination (what you see in the OUTPUT window.
2) Trafficlighting is only supported by ODS destinations that support style...so, for example...ODS HTML, ODS RTF, ODS PDF all support the use of style templates, while ODS CSV does not support the use of style templates
3) To see the trafficlighting applied, you have to look inside the final RESULT file, not inside the dataset (as with a data viewer):
[pre]
ODS HTML file='c:\temp\myresultfile.html' style=sasweb;

*** code with the trafficlighting/STYLE= syntax ;

ODS HTML CLOSE;
[/pre]
In this case, you would look in c:\temp\myresultfile.html with a browser to see the results of the trafficlighting.

Hope this helps,
cynthia
Ask a Question
Discussion stats
  • 2 replies
  • 121 views
  • 0 likes
  • 3 in conversation