Does SAS ods pdf can generate link to a page by the page number?
I have about 1000 pdf files generated by SAS before and now combined into one pdf files name "all_test.pdf". I want to create an contents and link to the specific page. I wrote a code as follows:
ods pdf file="contents.pdf";
data _null_;
length urlLink $48;
set ALL_TEST end=EOF;
if _N_ = 1 then do;
dcl odsout obj();
obj.format_text(data: "Special Test Case", just: "C", style_attr: "fontsize=12pt fontweight=bold height=24pt");
obj.table_start();
end;
PAGE_NUM = 2 + (_N_ - 1)*15;
urlLink = cats("URL='all_test.pdf#PAGE=",PAGE_NUM,"'");
obj.row_start();
obj.format_cell(data: TEST_NUM, style_attr: "fontsize=10pt height=20pt "||urlLink);
obj.row_end();
if eof then do;
obj.table_end();
obj.delete();
end;
run;
ods pdf close;
I insert this pdf to the first page of the all_test.pdf, all link works correct. However, if I rename the all_test.pdf to another name, for example, old_test.pdf, then the links were broken. I knew that because the link created in the table was tied with the name "all_test.pdf", but if I do not set the pdf name in the target, the link does not work anymore. And, I cannot find any SAS document about how to link to specific page by page number in the same pdf.
Any help? Thanks!
Hi:
I know of 2 ways and this tech support note http://support.sas.com/kb/24/174.html shows a 3rd way.
My methods are:
1) Use the default CONTENTS=YES so that the TOC on the first page takes you to the correct page
ods pdf file='c:\temp\default_links.pdf'
contents=yes;
proc print data=sashelp.class;
title 'Report SASHELP.CLASS';
run;
proc freq data=sashelp.class;
title 'Frequency SASHELP.CLASS';
tables age / nocum;
run;
ods pdf close;
title;
or 2) use ANCHOR= and LINK= (in a title) to control navigation.
ods pdf file='c:\temp\test_links.pdf'
anchor='REP' ;
proc print data=sashelp.class;
title 'Report SASHELP.CLASS';
title2 link='#FRQ' 'Go to Frequency for Age';
run;
ods pdf anchor='FRQ';
proc freq data=sashelp.class;
title 'Frequency SASHELP.CLASS';
title2 link='#REP' 'Go to Detail Report on Students';
tables age / nocum;
run;
ods pdf close;
title;
Notice how the ANCHOR= provides the string to use for the report and then you use that string with a # as a URL to link to the first page. If either report was multi-page, then the link would take you to the first page of the report.
I guess there's a 4th way with ODS DOCUMENT and PROC DOCUMENT, but I'm not sure it gives you more control than these 3 methods -- well, maybe more control in rearranging the structure of the output objects.
But with any of these methods, you have to put ALL the code that creates the separate reports in one ODS "sandwich" and even if you did use ODS DOCUMENT, then ALL the reports would need to be in an ODS DOCUMENT store.
Hope this helps
Cynthia
Thanks for the samples. I have noticed that in the link your provided. My problem is the other files were created already, I just want to generated a contents page only without recreated those files. Because there are no anchors were set when created those files, I can only refer to the page number. SAS looks only works with the hard coded PDF filename.
Thanks.
I finally recreated all file with anchors. it is a little time than created a content page using third party software because we need the information on that page which saved in sas data file.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.