Published on :
Reporting SASHELP

PDF Report Generation via ODS and Macros

This code is also available in: Deutsch Español Français
The script demonstrates the use of the ODS PDF destination to create paginated reports. It begins with a single report on filtered shoes. Then, it defines a macro '%loopTroughMake' that generates a car report for a specified make, with each report saved in a separate PDF file. The macro is called multiple times for different car makes, illustrating the dynamic generation of multiple PDF outputs.
Data Analysis

Type : SASHELP


The data comes exclusively from SASHELP libraries, specifically the SASHELP.SHOES and SASHELP.CARS datasets, which are built-in SAS sample datasets.

1 Code Block
PROC REPORT
Explanation :
This block initializes the ODS PDF destination to create the 'input_pdf_merge_1.pdf' file. It generates a simple report using 'PROC REPORT' on the SASHELP.SHOES dataset, filtering for 'Canada' and 'Pacific' regions, and displaying region, product, and sales.
Copied!
1ODS PDF FILE= "&out/input_pdf_merge_1.pdf" NOTOC;
2TITLE "Table 1: By Group Report about shoes";
3PROC REPORT DATA=sashelp.shoes(WHERE=(region IN ('Canada', 'Pacific'))) CONTENTS="";
4 BY region;
5 COLUMN region product sales;
6 DEFINE region / ORDER NOPRINT;
7RUN;
8ODS PDF CLOSE;
2 Code Block
Macro
Explanation :
Defines the '%loopTroughMake' macro which takes two parameters: 'make' (car brand) and 'i' (file/title number). For each call, it opens a new PDF file, creates a report with 'PROC REPORT' from SASHELP.CARS filtered by the specified make, then closes the PDF file. This allows for repeated report generation with different data.
Copied!
1%MACRO loopTroughMake(make,i);
2 ODS PDF FILE= "&out/input_pdf_merge_&i..pdf" NOTOC;
3 TITLE "Table &i: Multiple outputs - Cars for make = &make";
4 PROC REPORT DATA=sashelp.cars(WHERE=(make = "&make")) nowd headline spacing=2;
5 COLUMN make model type msrp;
6 RUN;
7 TITLE;
8 ODS PDF CLOSE;
9%MEND;
3 Code Block
Appel de macro
Explanation :
These lines call the '%loopTroughMake' macro three times with different car makes (Acura, Audi, BMW) and corresponding index numbers. Each call will generate a distinct PDF file containing a report on cars of the specified make.
Copied!
1%loopTroughMake(Acura,2);
2%loopTroughMake(Audi,3);
3%loopTroughMake(BMW,4);
4 
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Project : SMILE - SAS Macros, Intuitive Library Extension Author : Katja Glass Creation : 2021-02-18 License : MIT