As the first step in the decommissioning of sasCommunity.org 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
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.
- .pdf is typically handled by invoking Adobe Reader.
- .rtf is handled by invoking WordPad.
- .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. ; run; proc print data=sashelp.class(obs=5); run; %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; %reports(); ods html close; ods rtf; %reports(); ods rtf close; ods pdf; %reports(); ods pdf close; ods listing file="reports.wri"; %reports(); ods listing close; ods ps; %reports(); ods ps close; /* Going old school now. */ option ps=60 ls=73 nonumber; option FORMCHAR="|----|+|---+=|-/\<>*"; proc printto print = "sasprt.wri" new; %reports(); proc printto;
When the code above is run in batch (non-interactive) SAS, the following report files will be generated:
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.