Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_ds2pdf.sas File Reference

Create a PDF report from a dataset using ODS. More...

Go to the source code of this file.

Detailed Description

Renders a dataset as a paginated PDF with ODS PDF, so the output carries real typesetting - proportional fonts, repeated column headers on every page, titles, footnotes and page numbers - rather than a picture of a grid. Values are printed through PROC PRINT, so SAS formats and labels are applied to what the reader sees.

This is the server-side half of a download pair: send the result with mp_streamfile using contenttype=PDF.

Usage:

filename mypdf temp;
%mp_ds2pdf(sashelp.class, outref=mypdf
  ,title=Class listing
  ,footnote=Class table - generated &sysdate9);

%mp_streamfile(contenttype=PDF,inref=mypdf,outname=class.pdf)

Handling of the ODS session: the macro opens its own PDF destination, sets titles and footnotes for the duration of the report and clears them on the way out, so its own text does not leak into whatever the caller prints next. It does not save and restore the caller's titles, even though they can be read: SASHELP.VTITLE holds the current lines (TYPE T and F). Re-emitting them means rebuilding SAS statements out of free text that may contain quotes, semicolons or macro triggers, which is a separate problem this macro does not take on - so a caller that needs its own titles back after the report should capture them from SASHELP.VTITLE and set them again.

The page numbers are written with the (*ESC*) inline-function prefix rather than with an escape character, so the report does not depend on the caller having run ods escapechar=.

Parameters
[in]dsThe dataset to print. A name without a libref is read from WORK.
[out]outref=(pdfout) Fileref to contain the PDF. Assigned as a TEMP file if it is not already allocated.
[in]title=Optional report title, printed on every page.
[in]footnote=Optional footnote text. The page number is appended to it (see pagenum=), so pass the provenance here - dataset, filter, user, timestamp - and leave the numbering to the macro.
[in]by=Optional space separated BY variables. Each BY group starts a new page, so the data must already be sorted by those variables.
[in]maxobs=(0) Maximum number of observations to print. 0 prints every observation. Use it to cap very large tables, and say so in footnote= when a cap has been applied.
[in]options=Additional options for the ODS PDF statement, for example fontsize=9. The statement always carries notoc.
[in]style=Optional ODS style. Left to the site default when blank.
[in]orientation=(LANDSCAPE) Page orientation, one of LANDSCAPE or PORTRAIT. This is a SAS system option rather than an ODS PDF attribute, so the previous setting is restored on the way out.
[in]pagenum=(PAGE) Numbering appended to the footnote. Supported values:
  • PAGE - "Page n"
  • PAGEOF - "Page n of m"
  • NO - no page number The numbers come from the ODS inline functions {thispage} and {lastpage}, written behind the (*ESC*) prefix so no ODS ESCAPECHAR has to be set. SAS documents {lastpage} as preproduction, and warns that images and URL links can be dropped from a title or footnote that uses it - this macro prints a table only, so the total is safe here, but that is why it is not the default.
Returns
The PDF is written to outref. No dataset is created.

SAS Macros

Author
4GL Apps Ltd

Definition in file mp_ds2pdf.sas.