Monday, July 31, 2017

Hack 6.1 Adding Color to Report Titles with the ODS ESCAPECHAR Statement




SAS Programming Professionals,

Did you know that you can improve the look of your SAS-generated reports by adding a little color to the titles?

You can use the Output Delivery System (ODS) ESCAPECHAR statement and inline formatting to add and change colors within your report titles.  Here is an example:

ods escapechar = "^";

ods pdf file="example2.pdf";

title1 "^S={color=blue}Though this title started off blue ^S={color=red}it changed to red";
title2 "^S={color=green}This title was green ^S={}before changing to black";

proc print data=sashelp.class;
run;

ods _all_ close;

We start off with the ODS ESCAPECHAR statement, which defines a special character that will be used to signal to SAS that we want to perform inline formatting.  In our case, whenever SAS sees “^” in a title statement, it knows that ODS inline statements follow.  Thereafter, we put “^” to work in two TITLE statements; each time specifying the color for the following text.  If you copy the example above into a SAS Display Manager session and execute it, you will note the changes in the colors in the title lines.  Really makes you think about how you may be able to spruce-up those tired old reports, doesn’t it?

Best of luck in all your SAS endeavors!


---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers