As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Printing SAS reports from Windows Explorer

From sasCommunity
Jump to: navigation, search

On Windows, applications can register actions such as 'Open' or 'Print' for specific file extensions. In developing an approach to creating and then later on, printing SAS reports, it might be useful to exploit the 'Print' action on a report, invoked from Windows Explorer, in the day to day use of SAS.

Some file extensions have 'Print' actions that are well known.

  1. .pdf is typically handled by invoking Adobe Reader.
  2. .rtf is handled by invoking WordPad.
  3. .htm is handled by invoking a web browser.

With these conventions in mind, it's possible to explore several options for creating reports that can easily be printed from within Windows Explorer. Consider the following code:

%macro reports();
/* This snippet is from 'Speaking Klinkon: A translator's guide to PROC TABULATE' */
/* by Dianne Louise Rhodes                                                        */
proc tabulate data=sashelp.class;
   KEYLABEL n='No.' all='Total';
   CLASS age sex;
   TABLE (age all)*f=4. , sex*(N pctn<age all>)*f=4. ;
proc print data=sashelp.class(obs=5);
%mend reports;
/* If you're generating reports that ultimately need to be      */
/* printed, html is got a good choice of destination target.    */
/* Use PDF instead. This is included for completeness only,     */
/* not as a recommendation. It works, but don't do it.          */
ods html;
ods html close;
ods rtf;
ods rtf close;
ods pdf;
ods pdf close;
ods listing file="reports.wri";
ods listing close;
ods ps;
ods ps close;
/* Going old school now. */
option ps=60 ls=73 nonumber;
option FORMCHAR="|----|+|---+=|-/\<>*";
proc printto print = "sasprt.wri" new;
proc printto;

When the code above is run in batch (non-interactive) SAS, the following report files will be generated:

  1. sashtml.htm
  2. sasprt.pdf
  4. sasprt.wri
  5. reports.wri
  6. sasrtf.rtf

Printing these from Windows Explorer will generate a two-page report in each case. You are cautioned, however, against using the 'ods html' destination in this way. This ods destination is optimized for appearance in browsers, not printed pages.

Note that the file extension .wri was chosen for the text file, instead of say, .lst or .txt. This file extension identifies the file as a Microsoft Write file. Microsoft Write is no longer included in Windows. Instead, this file extension is handled by WordPad. In fact, the easiest way to bring up WordPad from a command line is to invoke 'write'. To invoke WordPad directly on a command line requires its full path. On Windows XP, the .wri file extesion will have a 'Print' action associated with WordPad. On Windows 7, this is no longer the case.

The .ps file extension approach may or may not be useful on a particular machine. Most machines won't have a utility installed that acts as a PostScript viewer. A 'Print' action will appear for .ps files if the free GSview utility is installed on the machine.

For the best results, targeting the ods pdf destination is recommended, if printing later from Windows Explorer is part of your SAS usage pattern.