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

Hello,

I am facing problems with the pdf output with several graphs included. I have two databases, from each of them I create by macro loop set of 6 graphs. I would like to have first 6 graphs on the page 1, graphs from the second loop on the second page. The pdf output I currently obtain contains several attributes I would like to change.

 

My issues are as follows:

 

1) If I run the code for the first time, there are no titles of the pages. All the graphs have its own - loop-specific - title, but there is no header of the pdf page. If I run the code for the second time, there is a header on each pdf page with the values of &saz and &taf from the second loop. Why is it so and is there some simple way how to create page-specific header ?

 

2) The second issue concerns the bookmarks. Each graph has its own clickable bookmark created by the command ods proclabel. But is there a way how to have just one bookmark per pdf page, not six the same ones ? The secondary bookmarks are hidden by the

command pdftoc = 1. Is there a way how to remove them totally ?

 

3) Despite the fact the loop runs 2 times, there are 3 pdf pages created. It seems it is because of the command ods pdf startpage=now. Is there a way how to remove the blank page (either at the beginning of the document or at the end depending on the location of the ods command) ?

 

Thank you for any suggestions which way to correct the code.

 

data out_i_a; set sashelp.retail; run;
data out_ii_b; set sashelp.retail; run; 

data y;
length saz tef x1 x2 $100;
input saz $ tef $ x1 $ x2; 
datalines;
I A desc1 desc1a
II B desc2 desc2a
;
run;


%macro jed();
proc sql;
    select count(*) into: pocet from y;
quit;

ods _all_ close;
options /*papersize="ISO A4"*/ orientation=portrait;
ods pdf file="\\srv35\\GRAF\AA_BB.pdf" /*style=bigger*/ pdftoc=1;
ods graphics / width=10cm height=8cm;

ods layout gridded columns=2;

%do i=1 %to &pocet;
title "TITLE - &saz. &tef.";

data _null_;
   set y (obs=&i);
   call symput("saz" ,strip(saz));
   call symput("tef" ,strip(tef));
   call symput("x1" ,strip(x1));
   call symput("x2" ,strip(x2));
run;

ods region;
ODS PROCLABEL "&saz. &tef. &x1.";
proc sgplot data=out_&saz._&tef.;
series x=date y=sales / legendlabel="sales"; 
series x=date y=year/y2axis legendlabel="year";
xaxis label="date";
yaxis label="sales";
y2axis label="year";
TITLE "&saz. &tef. Y1 - #";
run;

ods region;
ODS PROCLABEL "&saz. &tef. &x1.";
proc sgplot data=out_&saz._&tef.;
series x=date y=sales / legendlabel="sales"; 
series x=date y=year/y2axis legendlabel="year";
xaxis label="date";
yaxis label="sales";
y2axis label="year";
TITLE "&saz. &tef. Y1 - rate";
run;

ods region;
ODS PROCLABEL "&saz. &tef. &x1.";
proc sgplot data=out_&saz._&tef.;
series x=date y=sales / legendlabel="sales"; 
series x=date y=year/y2axis legendlabel="year";
xaxis label="date";
yaxis label="sales";
y2axis label="year";
TITLE "&saz. &tef. Y1 - #";
run;

ods region;
ODS PROCLABEL "&saz. &tef. &x1.";
proc sgplot data=out_&saz._&tef.;
series x=date y=sales / legendlabel="sales"; 
series x=date y=year/y2axis legendlabel="year";
xaxis label="date";
yaxis label="sales";
y2axis label="year";
TITLE "&saz. &tef. Y1 - rate";
run;

ods region;
ODS PROCLABEL "&saz. &tef. &x1.";
proc sgplot data=out_&saz._&tef.;
series x=date y=sales / legendlabel="sales"; 
series x=date y=year/y2axis legendlabel="year";
xaxis label="date";
yaxis label="sales";
y2axis label="year";
TITLE "&saz. &tef. Y1 - #";
run;

ods region;
ODS PROCLABEL "&saz. &tef. &x1.";
proc sgplot data=out_&saz._&tef.;
series x=date y=sales / legendlabel="sales"; 
series x=date y=year/y2axis legendlabel="year";
xaxis label="date";
yaxis label="sales";
y2axis label="year";
TITLE "&saz. &tef. Y1 - rate";
run;

ods pdf startpage=now; 
%end;
ods layout end;
ods pdf close;

%mend;
%jed;
1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

hi

 

I have made some changes to your code, see below.

To have an overall title for the page, use a TITLE statement before starting the layout.

 

Close a layout at the end of the page.

 

You can use ODS PDF BOOKMARKGEN and NOBOOKMARKGEN to control whether bookmarks are created or not.

 

You can use the DESCRIPTION option on Proc SGPLOT to control the text of the second level bookmark. 

 

data out_i_a;
  set sashelp.retail;
run;

data out_ii_b;
  set sashelp.retail;
run;

data y;
  length saz tef x1 x2 $100;
  input saz $ tef $ x1 $ x2;
  datalines;
I A desc1 desc1a
II B desc2 desc2a
;
run;

%macro jed();

  proc sql;
    select count(*) into: pocet from y;
  quit;

  ods _all_ close;
  options /*papersize="ISO A4"*/
  orientation=portrait;
  ods pdf file="c:\temp\AA_BB.pdf" /*style=bigger*/
  pdftoc=1;
  ods graphics / width=10cm height=8cm;

  /* overall title */
  %do i=1 %to &pocet;

    data _null_;
      set y (obs=&i);
      call symput("saz" ,strip(saz));
      call symput("tef" ,strip(tef));
      call symput("x1" ,strip(x1));
      call symput("x2" ,strip(x2));
    run;

    /* switch on bookmarks */
    ods pdf bookmarkgen;
    /* overall title before layout */
    title "TITLE - &saz. &tef.";
    ods layout gridded columns=2;
ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef. des="sugus";
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - #";
  run;
/* switch off bookmarks */
  ods pdf nobookmarkgen;
ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef.;
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - rate";
  run;

ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef.;
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - #";
  run;

ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef.;
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - rate";
  run;

ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef.;
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - #";
  run;

ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef.;
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - rate";
  run;
/* end layout at end of page */
ods layout end;
ods pdf startpage=now;
  %end;

  ods pdf close;
%mend;

%jed;

View solution in original post

3 REPLIES 3
BrunoMueller
SAS Super FREQ

hi

 

I have made some changes to your code, see below.

To have an overall title for the page, use a TITLE statement before starting the layout.

 

Close a layout at the end of the page.

 

You can use ODS PDF BOOKMARKGEN and NOBOOKMARKGEN to control whether bookmarks are created or not.

 

You can use the DESCRIPTION option on Proc SGPLOT to control the text of the second level bookmark. 

 

data out_i_a;
  set sashelp.retail;
run;

data out_ii_b;
  set sashelp.retail;
run;

data y;
  length saz tef x1 x2 $100;
  input saz $ tef $ x1 $ x2;
  datalines;
I A desc1 desc1a
II B desc2 desc2a
;
run;

%macro jed();

  proc sql;
    select count(*) into: pocet from y;
  quit;

  ods _all_ close;
  options /*papersize="ISO A4"*/
  orientation=portrait;
  ods pdf file="c:\temp\AA_BB.pdf" /*style=bigger*/
  pdftoc=1;
  ods graphics / width=10cm height=8cm;

  /* overall title */
  %do i=1 %to &pocet;

    data _null_;
      set y (obs=&i);
      call symput("saz" ,strip(saz));
      call symput("tef" ,strip(tef));
      call symput("x1" ,strip(x1));
      call symput("x2" ,strip(x2));
    run;

    /* switch on bookmarks */
    ods pdf bookmarkgen;
    /* overall title before layout */
    title "TITLE - &saz. &tef.";
    ods layout gridded columns=2;
ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef. des="sugus";
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - #";
  run;
/* switch off bookmarks */
  ods pdf nobookmarkgen;
ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef.;
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - rate";
  run;

ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef.;
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - #";
  run;

ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef.;
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - rate";
  run;

ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef.;
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - #";
  run;

ods region;
  ODS PROCLABEL "&saz. &tef. &x1.";

  proc sgplot data=out_&saz._&tef.;
    series x=date y=sales / legendlabel="sales";
    series x=date y=year/y2axis legendlabel="year";
    xaxis label="date";
    yaxis label="sales";
    y2axis label="year";
    TITLE "&saz. &tef. Y1 - rate";
  run;
/* end layout at end of page */
ods layout end;
ods pdf startpage=now;
  %end;

  ods pdf close;
%mend;

%jed;
jj_jj
Calcite | Level 5
Thank you a lot, I was getting a bit desparate.
jj_jj
Calcite | Level 5

I have broadened my problem and would be really thankful with any additional advice - https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/adding-page-just-with-the-text-to-the-ods-...

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
  • 3 replies
  • 2569 views
  • 1 like
  • 2 in conversation