Hello,
While attempting to create an automatic Table of Contents (TOC) for a PDF file, I encountered a few difficulties. The idea behind my TOC was to create an interactive TOC that includes the heading names and allows the user to navigate to the respective page with a mouse click. I was hoping that I may be able to customize the first proc report step of each page and change the name of this proc report step via the “ods proclabel = Header(1, 2, 3)” statement.
So far:
By running my code and using the "ods pdf" statements and the "contents = yes" option, an automatic TOC is generated, listing three levels with page numbers per Proc step. Using "ods proclabel = "header"", it is possible to name the first level as intended (Name of "Header"). By using the "contents = """ option for the respective Proc steps, it is possible to remove one of the three levels. However, I am not able to delete the unnecessary information or proc report steps left (e. g. “Proc report” or “Tabelle 1”). All yellow marked Information is declared as “unnecessary Information” (I just want to keep the renamed first proc report steps = "Header"):
Issues:
Questions:
And if the customization of the TOC does not work as I intended:
/* generate TOC */
libname verein 'yourpath';
/* Erstellung Beispieldaten in Libref "verein" */
data verein.beispieldaten;
Input Name $ Alter Geschlecht $ Monatsbeitrag Mitgliedsjahre;
Datalines;
Meier 56 M 10.10 26
Schmidt 50 W 65.02 7
Lehmann 45 W 71.20 6
Mueller 22 W 56 2
Johnson 19 M 26 1
Smith 23 M 80 2
Jones 80 W 60 11
;
run;
/*
-> ods proclabel = "Header" (first level TOC entry)
-> contents = "" (second-level TOC entry)
*/
/*** Produce report ***/
/** Define options **/
options nonumber orientation=portrait papersize=A4 nodate topmargin=.001in
bottommargin=.001in leftmargin=.001in rightmargin=.001in;
ods noproctitle;
ods escapechar="^";
ods noptitle;
options nonumber;
/*---------------------------------------------------------------------------------------------------------------------ods pdf start*/
ods pdf file="yourpath\TOC.pdf" startpage=no
contents=yes;
title;
/*------------------------------------------------------------------------------------------------------------------PAGE 1 */
ods pdf startpage=now;
ods layout start width=19cm height=28cm;
ods region y=3cm;
ods text="^{style[font_face='calibri' fontsize=12pt just=center fontweight=bold] Header_1}";
ods text=" ";
ods proclabel="Header_1";
proc report data=verein.beispieldaten contents="";
column Alter Mitgliedsjahre Monatsbeitrag;
define Alter/"Alter" display style(header)={just=c}
style(column)={just=center};
define Mitgliedsjahre/ style(header)={just=c} style(column)={just=center};
define Monatsbeitrag/ style(header)={just=c} style(column)={just=center};
run;
ods region y=7cm x=1.5cm;
ods text="Beispieltext 3";
ods region y=8cm x=3.5cm width=13cm height=8cm;
ods region y=18cm x=1cm;
ods proclabel="";
proc report data=verein.beispieldaten contents="";
column Alter Monatsbeitrag;
define Alter/"Alter" style(header)={just=l} style(column)={just=left};
define Monatsbeitrag/"Monatsbeitrag" style(header)={just=l}
style(column)={just=left};
run;
ods region y=27cm x=17cm;
ods text = "^{style[font_face='calibri' fontsize=9pt just=left fontweight=light] ^{thispage}}";
ods layout end;
/*---------------------------------------------------------------------------------------------------------------------PAGE 2*/
ods pdf startpage=now;
ods layout start width=19cm height=28cm;
ods region y=2cm x=1.5cm;
ods text="^{style[font_face='calibri' fontsize=12pt just=center fontweight=bold] Header_2}";
ods region y=3cm x=1cm;
ods proclabel="Header_2";
proc report data=verein.beispieldaten contents="";
column Name Geschlecht Alter;
define Name/"Name" style(header)={just=l} style(column)={just=left};
define Geschlecht/"Geschlecht" style(header)={just=l}
style(column)={just=center};
define Alter/"Alter" style(header)={just=l} style(column)={just=center};
run;
ods proclabel="";
proc report data=verein.beispieldaten contents="";
column Alter Mitgliedsjahre Monatsbeitrag;
define Alter/"Alter" display style(header)={just=c}
style(column)={just=center};
define Mitgliedsjahre/ style(header)={just=c} style(column)={just=center};
define Monatsbeitrag/ style(header)={just=c} style(column)={just=center};
run;
ods region y=27cm x=17cm;
ods text = "^{style[font_face='calibri' fontsize=9pt just=left fontweight=light] ^{thispage}}";
ods layout end;
ods layout end;
/*---------------------------------------------------------------------------------------------------------------------PAGE 3*/
ods pdf startpage=now;
ods layout start width=19cm height=28cm;
ods region y=2cm x=1.5cm;
ods text="^{style[font_face='calibri' fontsize=12pt just=center fontweight=bold] Header_3}";
ods region y=3cm x=1cm;
ods proclabel="Header_3";
proc report data=verein.beispieldaten contents="";
title "Titel";
column Name Geschlecht Alter;
define Name/"Name" style(header)={just=l} style(column)={just=left};
define Geschlecht/"Geschlecht" style(header)={just=l}
style(column)={just=center};
define Alter/"Alter" style(header)={just=l} style(column)={just=center};
run;
ods proclabel="";
proc report data=verein.beispieldaten contents="";
title "Titel";
column Alter Mitgliedsjahre Monatsbeitrag;
define Alter/"Alter" display style(header)={just=c}
style(column)={just=center};
define Mitgliedsjahre/ style(header)={just=c} style(column)={just=center};
define Monatsbeitrag/ style(header)={just=c} style(column)={just=center};
run;
ods region y=27cm x=17cm;
ods text = "^{style[font_face='calibri' fontsize=9pt just=left fontweight=light] ^{thispage}}";
ods layout end;
ods layout end;
ods pdf close;
I would greatly appreciate any suggestions, hints, or alternative solutions. Thank you very much!
Here is an example based on the following SAS Note that eliminates the third node:
data class;
set sashelp.class;
count=1;
run;
ods listing close;
ods pdf file='test.pdf' contents=yes;
ods proclabel='Header 1';
proc report data=class contents='';
column count name age height weight;
define count / order noprint;
break before count / contents='' page;
run;
ods pdf close;
ods listing;
Here is an example based on the following SAS Note that eliminates the third node:
data class;
set sashelp.class;
count=1;
run;
ods listing close;
ods pdf file='test.pdf' contents=yes;
ods proclabel='Header 1';
proc report data=class contents='';
column count name age height weight;
define count / order noprint;
break before count / contents='' page;
run;
ods pdf close;
ods listing;
That worked just as intended, thank you so much!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.