The SAS Output Delivery System and reporting techniques

issues with pdf output using sgplot

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

issues with pdf output using sgplot

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;

Accepted Solutions
Solution
2 weeks ago
SAS Super FREQ
Posts: 785

Re: issues with pdf output using sgplot

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


All Replies
Solution
2 weeks ago
SAS Super FREQ
Posts: 785

Re: issues with pdf output using sgplot

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

Re: issues with pdf output using sgplot

Posted in reply to Bruno_SAS
Thank you a lot, I was getting a bit desparate.
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 174 views
  • 1 like
  • 2 in conversation