BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
laura6728
Obsidian | Level 7

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;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

6 REPLIES 6
ballardw
Super User

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

 

Remove it.

laura6728
Obsidian | Level 7
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.
ballardw
Super User

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;
laura6728
Obsidian | Level 7

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.

ballardw
Super User

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).

laura6728
Obsidian | Level 7

This worked perfectly, thank you so much!!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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