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


Monday, July 10, 2017

Hack 5.5 Using Macros to Comment Out Sections of SAS Programs



SAS Programming Professionals,

Did you know that you can use SAS macros as a handy way to comment out code in a program?

You can do this by enclosing portions in a SAS macro and not calling that macro.  Here is an example:

options msglevel=I;

%MACRO HIDEIT;

libname audit "H:\My Documents\My SAS Programs\Audit Trails\Data";

proc copy in=sashelp out=audit;
      select orsales;
run;

data audit.orsales;

seqno = _n_;

set  audit.orsales;

run;

%MEND HIDEIT;

data audit.orsales2;
set  audit.orsales;
stop;
run;

proc datasets library=audit nolist;
      audit orsales2;
      initiate;
      log admin_image=yes
      before_image=yes
      data_image=no
      error_image=yes;
run;
quit;

In this example, we wish to not execute (to hide) the LIBNAME statement, PROC COPY, and the DATA step as we test the latter sections of our program.  So, after they are first executed, we enclose them in the HIDEIT macro.  Thereafter, when we run this program, the aforementioned SAS constructs do not execute.  Once we are done testing the program, we can either comment out the %MACRO and %MEND statements or delete them entirely.  Pretty clever, eh?

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