The SAS Output Delivery System and reporting techniques

ODS pdf with 2 proc prints in same page with by groups

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

ODS pdf with 2 proc prints in same page with by groups

In the code below my intent is to have the two proc prints print on either the same page or one on page one & the other on page two of a pdf document.  I have by groups on both proc print statements, but what I end up with is 50+ pdfs. 2 per by group, one with the 1st proc print and one with the 2nd proc print.  Is there a way to have them both print on the same, and keep the by groupings?  I have read several articles using regions, listings and/or macros and none would give me what I was really looking for, and I think it is my groupings messing it up.  Tips/ideas?

 

ods pdf file="\\MCC-DATA\IEDATA\Projects\CE_Evals\&YEAR.&QUARTER.\summary.pdf"
newfile=bygroup
startpage=yes
notoc
style=MyJournal3;

OPTIONS NONUMBER NODATE;

TITLE "Summary Results for Continuing Education Courses Taught During &YEAR. - &QUARTER.";

PROC PRINT
DATA=WORK.RESULTS_TOTALS LABEL WIDTH=FULL NOOBS;
BY TITLE INSTRUCTOR;
WHERE QUESTION <= 'Q14';

VAR QUESTION SA PERCENT_SA A PERCENT_A D PERCENT_D SD PERCENT_SD;

	LABEL SA = 'Strongly Agree'
		  PERCENT_SA = '% Strongly Agree'
		  A = 'Agree'
		  PERCENT_A = '% Agree'
		  D = 'Disagree'
		  PERCENT_D = '% Disagree'
		  SD = 'Strongly Disagree'
		  PERCENT_SD = '% Strongly Disagree'
		  TITLE = 'Course'
		  INSTRUCTOR = 'Instructor';

RUN;

PROC PRINT
DATA=WORK.RESULTS_TOTALS LABEL NOOBS;
BY TITLE INSTRUCTOR;
WHERE QUESTION = 'Q15';

VAR QUESTION EX PERCENT_EX GD PERCENT_GD AV PERCENT_AV BAV PERCENT_BAV PR PERCENT_PR;

	LABEL EX = 'Excellent'
		  PERCENT_EX = '% Excellent'
		  GD = 'Good'
		  PERCENT_GD = '% Good'
		  AV = 'Average'
		  PERCENT_AV = '% Average'
		  BAV = 'Below Average'
		  PERCENT_BAV = '% Below Average'
		  PR = 'Poor'
		  PERCENT_PR = '% Poor';

RUN;

ods pdf close;

Accepted Solutions
Solution
‎05-13-2016 12:18 PM
Grand Advisor
Posts: 10,215

Re: ODS pdf with 2 proc prints in same page with by groups

You are actually attempting to interleave the results from two procedures if I understand what you are saying. First by group values from the first proc print followed by the same by group of the second proc print, then the next by group from the first proc print and then the second by group from the second proc print.

If that is the case then you have more work ahead. Try this untested code as I don't have your data set:

 

proc sql;
   create table Control as 
   select distinct title,Instructor
   from work.results_totals;
quit;
data _null;
   set control;
   Length lstr $ 200;
   call execute ('PROC PRINT');
   call execute ('DATA=WORK.RESULTS_TOTALS LABEL WIDTH=FULL NOOBS;');
   lstr = catx(' ','Title','"Title=',title,'Instructor=',Instructor,'";');
   call execute (Lstr );
   lstr = catt('Where Question <="Q14" and Title="',title,'" and Instructor="',Instructor,'";'); 
   call execute (Lstr );
   call execute ('VAR QUESTION SA PERCENT_SA A PERCENT_A D PERCENT_D SD PERCENT_SD;');
   call execute ("LABEL SA = 'Strongly Agree'");
   call execute ("PERCENT_SA = '% Strongly Agree'");
   call execute ("A = 'Agree'");
   call execute ("PERCENT_A = '% Agree'");
   call execute ("D = 'Disagree'");
   call execute ("PERCENT_D = '% Disagree'");
   call execute ("SD = 'Strongly Disagree'");
   call execute ("PERCENT_SD = '% Strongly Disagree'");
   call execute ("TITLE = 'Course'");
   call execute ("INSTRUCTOR = 'Instructor';");
   call execute ("RUN;");

   call execute ('PROC PRINT');
   call execute ('DATA=WORK.RESULTS_TOTALS LABEL NOOBS;');
   lstr = catx(' ','Title','"Title=',title,'Instructor=',Instructor,'";');
   call execute (Lstr );
   lstr = catt('Where Question ="Q15" and Title="',title,'" and Instructor="',Instructor,'";'); 
   call execute (Lstr );
   call execute ("VAR QUESTION EX PERCENT_EX GD PERCENT_GD AV PERCENT_AV BAV PERCENT_BAV PR PERCENT_PR;");

   call execute ("LABEL EX = 'Excellent'");
   call execute ("PERCENT_EX = '% Excellent'");
   call execute ("GD = 'Good'");
   call execute ("PERCENT_GD = '% Good'");
   call execute ("AV = 'Average'");
   call execute ("PERCENT_AV = '% Average'");
   call execute ("BAV = 'Below Average'");
   call execute ("PERCENT_BAV = '% Below Average'");
   call execute ("PR = 'Poor'");
   call execute ("PERCENT_PR = '% Poor';");
   call execute ("RUN;");
run;

View solution in original post


All Replies
Grand Advisor
Posts: 10,215

Re: ODS pdf with 2 proc prints in same page with by groups

The option newfile=bygroup instructs ODS to create one file for each by group.

 

Remove it.

Contributor
Posts: 24

Re: ODS pdf with 2 proc prints in same page with by groups

Unfortunately that doesn't work either. It puts all my procs into one file, but all the tables from the first proc print, then all the tables from the second. I want the table from proc print 1 & print 2 to show on one page per by grouping.
Solution
‎05-13-2016 12:18 PM
Grand Advisor
Posts: 10,215

Re: ODS pdf with 2 proc prints in same page with by groups

You are actually attempting to interleave the results from two procedures if I understand what you are saying. First by group values from the first proc print followed by the same by group of the second proc print, then the next by group from the first proc print and then the second by group from the second proc print.

If that is the case then you have more work ahead. Try this untested code as I don't have your data set:

 

proc sql;
   create table Control as 
   select distinct title,Instructor
   from work.results_totals;
quit;
data _null;
   set control;
   Length lstr $ 200;
   call execute ('PROC PRINT');
   call execute ('DATA=WORK.RESULTS_TOTALS LABEL WIDTH=FULL NOOBS;');
   lstr = catx(' ','Title','"Title=',title,'Instructor=',Instructor,'";');
   call execute (Lstr );
   lstr = catt('Where Question <="Q14" and Title="',title,'" and Instructor="',Instructor,'";'); 
   call execute (Lstr );
   call execute ('VAR QUESTION SA PERCENT_SA A PERCENT_A D PERCENT_D SD PERCENT_SD;');
   call execute ("LABEL SA = 'Strongly Agree'");
   call execute ("PERCENT_SA = '% Strongly Agree'");
   call execute ("A = 'Agree'");
   call execute ("PERCENT_A = '% Agree'");
   call execute ("D = 'Disagree'");
   call execute ("PERCENT_D = '% Disagree'");
   call execute ("SD = 'Strongly Disagree'");
   call execute ("PERCENT_SD = '% Strongly Disagree'");
   call execute ("TITLE = 'Course'");
   call execute ("INSTRUCTOR = 'Instructor';");
   call execute ("RUN;");

   call execute ('PROC PRINT');
   call execute ('DATA=WORK.RESULTS_TOTALS LABEL NOOBS;');
   lstr = catx(' ','Title','"Title=',title,'Instructor=',Instructor,'";');
   call execute (Lstr );
   lstr = catt('Where Question ="Q15" and Title="',title,'" and Instructor="',Instructor,'";'); 
   call execute (Lstr );
   call execute ("VAR QUESTION EX PERCENT_EX GD PERCENT_GD AV PERCENT_AV BAV PERCENT_BAV PR PERCENT_PR;");

   call execute ("LABEL EX = 'Excellent'");
   call execute ("PERCENT_EX = '% Excellent'");
   call execute ("GD = 'Good'");
   call execute ("PERCENT_GD = '% Good'");
   call execute ("AV = 'Average'");
   call execute ("PERCENT_AV = '% Average'");
   call execute ("BAV = 'Below Average'");
   call execute ("PERCENT_BAV = '% Below Average'");
   call execute ("PR = 'Poor'");
   call execute ("PERCENT_PR = '% Poor';");
   call execute ("RUN;");
run;
Contributor
Posts: 24

Re: ODS pdf with 2 proc prints in same page with by groups

This is getting me towards what I am looking for!! Thank you so much! One last question, is it possible to do a file break after the end of the last call execute? This is putting the file in the correct order which, is great because then even if I have to manually break up the pdf file, that's a lot easier than reorganizing or recompiling files.

Grand Advisor
Posts: 10,215

Re: ODS pdf with 2 proc prints in same page with by groups

I don't use PDF much put I think if you add:

Call execute("ODS PDF Startpage=Now;"); that will insert a page break after the second proc print.

But you will need to have

Call execute ("ODS PDF Startpage=No;"); before the first Proc print to give a chance to get both proc print on one page (or minimum space between them if they run longer).

Contributor
Posts: 24

Re: ODS pdf with 2 proc prints in same page with by groups

This worked perfectly, thank you so much!!

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 455 views
  • 2 likes
  • 2 in conversation