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!
ODS PDF FILE= "&out/input_pdf_merge_1.pdf" NOTOC;
TITLE "Table 1: By Group Report about shoes";
PROC REPORT DATA=sashelp.shoes(WHERE=(region IN ('Canada', 'Pacific'))) CONTENTS="";
BY region;
COLUMN region product sales;
DEFINE region / ORDER NOPRINT;
RUN;
ODS PDF CLOSE;
1
ODS PDF FILE= "&out/input_pdf_merge_1.pdf" NOTOC;
2
TITLE "Table 1: By Group Report about shoes";
3
PROC REPORTDATA=sashelp.shoes(WHERE=(region IN ('Canada', 'Pacific'))) CONTENTS="";
4
BY region;
5
COLUMN region product sales;
6
DEFINE region / ORDER NOPRINT;
7
RUN;
8
ODS 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!
%MACRO loopTroughMake(make,i);
ODS PDF FILE= "&out/input_pdf_merge_&i..pdf" NOTOC;
TITLE "Table &i: Multiple outputs - Cars for make = &make";
PROC REPORT DATA=sashelp.cars(WHERE=(make = "&make")) nowd headline spacing=2;
COLUMN make model type msrp;
RUN;
TITLE;
ODS PDF CLOSE;
%MEND;
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";
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.
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
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.