Hello,
I have a problem that I can't solve properly if anyone can help.
I'm working on automatizing pdf outputs using ods pdf and proc report.
I have two data sets Data1 and Data2. I want to produce pdf files using a table from Data1 and another table from Data2. I use the option 'newfile=bygroup' as the same groups are in both datasets. I would like to put both tables in the same page (pdf).
Here's the code of what i do:
options nodate nonumber;
ods pdf file="...../MyPDF1.pdf" style=sasref newfile=bygroup;
proc report data=Data1 nowd;
by myGroup;
........
proc report data=Data2 nowd;
by myGroup;
.......
run;
ods pdf close;
run;
By doing this, i produce pdf files by group but separately from each data set. I would like to put for each group the two tables together in one page.
It would be helpful if anyone has an isea or a hint.
Thanks.
Below is a macro that should help with your request of getting both Proc Report outputs on one PDF file and also renames the PDF output based on the group number. You don't need the Proc SQL code if you already know what the first and last group numbers are. But you can use it if you want SAS to automate the values for the do loop if this is always changing. "Startpage = Never" option on the ods pdf statement is used to not create a page break between the output. Hopefully this works for you.
options nodate nonumber; %macro reporting; proc sql; select min(mygroup),max(mygroup) into :firstgrp, :lastgrp from Data1; quit; %do i = &firstgrp. %to &lastgrp.; ods pdf file="...../MyPDF1 - Group &i..pdf" style=sasref startpage=never; proc report data=Data1 nowd; where myGroup = &i.; by myGroup; ........
run;
proc report data=Data2 nowd; where myGroup = &i.; by myGroup; ....... run; ods pdf close; %end; %mend reporting; %reporting;
Unfortunately that won't work with the newfile option and you'll have to write a macro 😞
Below is a macro that should help with your request of getting both Proc Report outputs on one PDF file and also renames the PDF output based on the group number. You don't need the Proc SQL code if you already know what the first and last group numbers are. But you can use it if you want SAS to automate the values for the do loop if this is always changing. "Startpage = Never" option on the ods pdf statement is used to not create a page break between the output. Hopefully this works for you.
options nodate nonumber; %macro reporting; proc sql; select min(mygroup),max(mygroup) into :firstgrp, :lastgrp from Data1; quit; %do i = &firstgrp. %to &lastgrp.; ods pdf file="...../MyPDF1 - Group &i..pdf" style=sasref startpage=never; proc report data=Data1 nowd; where myGroup = &i.; by myGroup; ........
run;
proc report data=Data2 nowd; where myGroup = &i.; by myGroup; ....... run; ods pdf close; %end; %mend reporting; %reporting;
I think you'd only need the WHERE clause, not both the WHERE and BY.
where myGroup = &i.;
by myGroup;
I think you'd only need the WHERE clause, not both the WHERE and BY.
where myGroup = &i.;
by myGroup;
That is correct. Thanks for pointing that out. I guess I am used to sorting by another variable.
It works, thank you!
Basically, 'myGroup' is a character type (a name), so i just introduced a variable of counting fllowing myGroup and used it instead of myGroup. Unfotunately, the name of PDF is a number now. It would be perfect if i can name the file with the name of myGroup. Any idea?
Thank you again!!
The easiest way to get the name of the group in the pdf filename is to incorporate a proc sql to create a macro variable based on the group name in the do loop. That way you can use the group name macro variable in the ods pdf file statement.
%do i = &firstgrp. %to &lastgrp.; proc sql; select distinct(mygroup) into :grpname from Data1 where mygroup = &i.; quit; ods pdf file="...../MyPDF1 - &grpname..pdf" style=sasref startpage=never;
Hello,
I use a proc template (that i use in the code : style = sasref) to manipulate the output of my tables, but it seems that i can't use different templates for my two tables; is there a possibility to use different templates for different tables created in one pdf page?
Thank you.
@imathThis is a new question, I would recommend a new thread.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: