The SAS Output Delivery System and reporting techniques

two tables in ods pdf (bygroup)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

two tables in ods pdf (bygroup)

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.


Accepted Solutions
Solution
‎03-02-2016 07:33 AM
Occasional Contributor
Posts: 18

Re: two tables in ods pdf (bygroup)

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;

 

View solution in original post


All Replies
Super User
Posts: 19,789

Re: two tables in ods pdf (bygroup)

Unfortunately that won't work with the newfile option and you'll have to write a macro Smiley Sad

 

 

Solution
‎03-02-2016 07:33 AM
Occasional Contributor
Posts: 18

Re: two tables in ods pdf (bygroup)

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;

 

Super User
Posts: 19,789

Re: two tables in ods pdf (bygroup)

I think you'd only need the WHERE clause, not both the WHERE and BY.

 

		    where myGroup = &i.;
		    by myGroup;
Super User
Posts: 19,789

Re: two tables in ods pdf (bygroup)

I think you'd only need the WHERE clause, not both the WHERE and BY.

 

		    where myGroup = &i.;
		    by myGroup;
Occasional Contributor
Posts: 18

Re: two tables in ods pdf (bygroup)

That is correct. Thanks for pointing that out. I guess I am used to sorting by another variable. 

Occasional Contributor
Posts: 7

Re: two tables in ods pdf (bygroup)

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!!

Occasional Contributor
Posts: 18

Re: two tables in ods pdf (bygroup)

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;
Occasional Contributor
Posts: 7

Re: two tables in ods pdf (bygroup)

Perfect! Thank you so much!

Spoiler
 

Smiley Happy

Occasional Contributor
Posts: 7

Re: two tables in ods pdf (bygroup)

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.

Super User
Posts: 19,789

Re: two tables in ods pdf (bygroup)

@imathThis is a new question, I would recommend a new thread.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 957 views
  • 2 likes
  • 3 in conversation