Monday, October 30, 2017

Hack 6.5 Jazzing Up Reports Using ODS Style Templates



SAS Programming Professionals,

The Output Delivery System (ODS) utilizes style templates (sometimes called “style definitions”) to render output.  Style templates describe the font face, size, color, and other attributes that are to be used when a report is rendered.  SAS currently has 58 individual style templates available for your use; and more are sure to be added moving forward.  If you do not specify a style template in your SAS program, ODS uses the aptly named Default style template.  Most of the time, Default is satisfactory.  However, there are some very nice alternatives!

You can get a listing of all of the style templates available to you by submitting the following:

proc template;

list styles;

run;

The output looks, in part, like this:

       Obs    Path                         Type
       -----------------------------------------
       1     Styles                       Dir
       2     Styles.Analysis              Style
       3     Styles.Astronomy             Style
       4     Styles.Banker                Style
       5     Styles.BarrettsBlue          Style
       6     Styles.Beige                 Style
       .     ...                            ...

…where the style templates are Analysis, Astronomy, Banker, etc.

To see the effect of changing the style template, first copy the following code into a SAS session, run it, and look at the resulting RTF file:

options nodate nonumber;

ods Listing close;
ods RTF  file="c:\temp\Class_Report.rtf”;

    proc print data=sashelp.class  noobs n;
      title1 "Report of Class Weight/Height Study";
    run;

ods RTF close;
ods Listing;

Not bad.  No surprises there, right?

Now, run this code that has the Astronomy style template specified:

options nodate nonumber;

ods Listing close;
ods RTF  file="c:\temp\Class_Report.rtf" style=astronomy;

    proc print data=sashelp.class  noobs n;
      title1 "Report of Class Weight/Height Study";
    run;

ods RTF close;
ods Listing;

Very nice departure from the default, isn’t it?  Well, you have 56 more styles (…because one style is the Default; which you previously used) to try, so I am sure that you will find one that is just perfect for your team and your client!

It’s nice to see a bit of color in your reports, isn’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

Tuesday, October 17, 2017

Hack 6.4 Inserting the SAS Date and Time into an RTF Document



SAS Programming Professionals,

Did you know that you can insert the standard SAS date and time into a new RTF document in place of the default RTF specification that inserts the printing date and time?

This is a bit hard to visualize, but stick with me; it’s worth it! 

If you were to submit the follow simple program at 8:00am this morning:

ods rtf file="rtfdate2.rtf";

proc print data=sashelp.class;
run;

ods rtf close;

…you would create an RTF document that would have the date/time embedded as a header in the upper right hand side.  If you were to open that file at 11:00am this morning, the header would read:

11:00 Monday, December 12, 2015  1

…even thought it was actually created at 8:00am this morning.  If you were to print the document at 11:30 this morning, the header on the printed page would read:

11:30 Monday, December 12, 2015  1

…even though it was actually created at 8:00am this morning and you opened the file at 11:00am this morning. 

Now, what’s wrong with this picture?  Well, nothing if you want the RTF default header date/time in effect.  However, if you want to document the date/time this document was actually created, then code the SASDATE option in the ODS statement.  Here is an example using the same program as before:

ods rtf file="sasdate.rtf" sasdate;

proc print data=sashelp.class;
run;

ods rtf close ;

If you were to submit that at 8:00am this morning, then whenever you open it up, you will see the following header:

8:00 Monday, December 12, 2015  1

Similarly, whenever you print the document, that will be the header in the hard copy.  This will happen each and every time that you open the file and that you print the file.

So, the SASDATE option on the ODS FILE= statement “freezes” the date/time the RTF document was created.  Nine times out of ten, that is exactly the behavior that I want!  And you?

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, October 2, 2017

Hack 6.3 Customizing Footnotes For More Professional Looking Reports



SAS Programming Professionals,

Did you know that you can make your reports look more professional by customizing the footnotes?

Sometimes, too much information at the top of a report can make it look a bit cluttered.  SAS-generated reports often have the date and time they were created, as well as the page number, on the upper right-hand side of their pages.  They also tend to have several lines of titles describing the general content of the report.

Wouldn’t it be cleaner to put the report’s creation date and page numbers on the bottom?  And, wouldn’t it be nice to show your clients which relative page they are viewing by having “page x of y” as the page specification?  If the answer to both of these questions is “Yes”, then take a look at this example:

ods pdf file="c:\temp\car_report.pdf";
ods escapchar="^";

options nodate nonumber;

proc print noobs data=sashelp.cars;

      var make model msrp;

title "Important Cars Report";

footnote1 j=l '^{thispage} of ^{lastpage}' j=r "Report Date: 

%sysfunc(date(),worddate.)";

run;

ods pdf close;

We start off with an ODS statement that specifies a new PDF document that will house our report.  The second ODS statement specifies the ESCAPECHAR—a symbol telling ODS that what follows is an instruction, not something to be printed.  The OPTIONS statement directs SAS to not write the date/time and page number at the top of the report.  Less clutter!

The important action takes place in the FOOTNOTE statement:

·        j=l tells SAS to left justify the following section of the footnote.


·        ‘^{thispage} of ^{lastpage}’ – the THISPAGE function inserts the current page number; the LASTPAGE function inserts the last page number.

·        j=r specifies for the following section of the footnote  to be right justified.

·        "Report Date:  %sysfunc(date(),worddate.)" – surfaces the current date and formats that date using the WORDDATE format.

Copy the example, above into a SAS Display Manager Session and give it a test drive.  Nice report, eh?  Note the cleaner look at the top and the more professional look at the bottom.  Maybe you can use this technique to improve the look of some of your own projects’ reports!

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