Here I'm using proc report with a by statement and proc document to create a table of contents in a PDF file.
I'm wondering why "Level 3" is not displayed by in the list statement output of proc document
and why renaming the Table Item with setlabel creates a new item in the TOC.
1. Default Labels in the TOC
proc sort data=sashelp.class out=class;
by sex;
run;
ods document name=test(write);
proc report data=class;
by sex;
column name age height weight;
define name / display;
define age / display;
define height / display;
define weight / display;
run;
ods document close;
ods pdf file ="&xxtest./reporting/test.pdf";
proc document name=test;
replay;
run;
quit;
ods pdf close;
2. Using labels from proclabel and contents
options label;
proc sort data=sashelp.class out=class;
by sex;
run;
data class;
set class;
retain tmp 1;
run;
ods document name=test(write);
ods proclabel 'Level 1';
proc report data=class contents='Level 2';
by sex;
column tmp name age height weight;
define tmp / order noprint;
define name / display;
define age / display;
define height / display;
define weight / display;
break before tmp / page contents='Level 3';
run;
ods document close;
ods pdf file ="&xxtest./reporting/test.pdf";
proc document name=test;
replay;
run;
quit;
ods pdf close;
3. Using proc document
options label;
proc sort data=sashelp.class out=class;
by sex;
run;
data class;
set class;
retain tmp 1;
run;
ods document name=test(write);
ods proclabel 'Level 1';
proc report data=class contents='Level 2';
by sex;
column tmp name age height weight;
define tmp / order noprint;
define name / display;
define age / display;
define height / display;
define weight / display;
break before tmp / page contents='Level 3';
run;
ods document close;
proc document name=test;
list/levels=all details;
run;
quit;
proc document name=test;
setlabel \Report#1\ByGroup1#1\Report#1\Report#1 '4.1';
setlabel \Report#1\ByGroup2#1\Report#1\Report#1 '4.2';
setlabel \Report#1\ByGroup1#1\Report#1 '3.1';
setlabel \Report#1\ByGroup2#1\Report#1 '3.2';
setlabel \Report#1\ByGroup1#1 '2.1';
setlabel \Report#1\ByGroup2#1 '2.2';
setlabel \Report#1 '1';
list/levels=all details;
run;
quit;
ods pdf file ="&xxtest./reporting/test.pdf";
proc document name=test;
replay;
run;
quit;
ods pdf close;
I'm wondering why "Level 3" is not displayed in the list statement output.
We can see that renaming the Table item creates a new entry on the last level rather than the one available at that level.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.