Tables of contents with hyperlink in Ods pdf - sas

I am trying to create a table of contents with hyperlink in Ods pdf.My requirements are I want a table of contents with page no as well as hyperlink also.
I have try two methods.
I have created table of contents with datalines in which I have used ods pdf anchor to create hyperlink in pdf report but I am not getting page no.
I have used ods proclabel to create table of contents in that I am getting page no but not getting hyperlink

Here is a sample of 2). ODS PDF CONTENTS creates a TOC with entries that are the bookmark items, however none of the items or page numbers are hyperlinks. I don't think there is an ODS feature that lets you specify that PDF TOC entries should also be hyperlinks.
ods _all_ close;
ods pdf
file="%sysfunc(pathname(WORK))\sample-%sysfunc(monotonic()).pdf"
contents=yes %* specify TOC be generated, can also specify with CONTENTS/NOCONTENTS;
;
ods proclabel "SASHELP.CLASS listing"; * Bookmark level 1;
title "SASHELP.CLASS";
options nodate nonumber;
proc print noobs data=sashelp.class
contents='' %* option as empty-string removes bookmark level 2;
;
run;
ods proclabel "SASHELP gender counts";
title "Gender frequency";
proc sgplot data=sashelp.class
description="Simple bar chart" %* option sets bookmark level 2;
;
vbar sex ;
run;
ods pdf close;

Related

SAS ODS RTF Table column header

I am creating a RTF file using SAS ODS. When I add a text using "ODS TEXT", the column headers of a table are not repeating in next page but comes only at the start of the table.
When I remove the "ODS TEXT", I get columns names in all pages. Since I need a text above the table (not in header/title), can you suggest a solution?
data chk;
set sashelp.class;
output; output;
run;
ods rtf file = "xx\check.rtf";
ods escapechar = '^';
title " ";
ods text="ods text";
proc report nowd data=chk ;
run;
ods rtf close;

Output distribution charts in a pdf format? I only need the chart from a proc univariate of all the variables in a table

How can I output distribution charts in a pdf format? I only need the chart from a proc univariate of all the variables in a table - not any additional metrics.
ods pdf file="aaaa.pdf
TITLE 'Summary of Weight Variable (in pounds)';
PROC UNIVARIATE DATA = sashelp.class NOPRINT;
HISTOGRAM _all_ / NORMAL;
RUN;
ods pdf close
You use ODS SELECT _chartname_ to limit the output to what you want. You need to remove the NOPRINT option though or no output is generated to display regardless of destination.
It looks like univariate produces: CDFPlot, Histogram, PPplot, Probplot, QQplot so assuming you want just the histogram add the following line to your code:
ods select histogram;
Full code:
ods pdf file="aaaa.pdf;
ods select histogram;
TITLE 'Summary of Weight Variable (in pounds)';
PROC UNIVARIATE DATA = sashelp.class ;
HISTOGRAM _all_ / NORMAL;
RUN;
ods pdf close
Add it before or within your PROC UNIVARIATE.
PS. You're missing a semicolon on your ODS PDF statements at the top and bottom.
A good blog post from the SAS website on this is available here.

SAS regression result output to excel in one sheet

I want to output my SAS regression result into excel.
The code is:
proc import datafile = 'cmds.csv'
out = Work.cmds
dbms = CSV;
run;
ODS TAGSETS.EXCELXP
file="dt.xls";
STYLE = STATISTICAL;
proc sort data=Work.Cmds out=Work.Cmds;
by year;
run;
proc reg data=Work.Cmds outest=want tableout;
by year;
model Investment = Size Growth_New Leverage complex Deficit pc_income_NEW Density/hcc adjrsq ;
ods output parameterestimates=want2;
run;
ODS TAGSETS.EXCELXP CLOSE;
Although it successfully generates the excel file, it contains many sheets. I want to generate all things in one sheet. How can I do?
There are options within the tagsets, in specific sheet_interval. To have all go to one page, set the sheet interval option to none.
ODS TAGSETS.EXCELXP file="dt.xls" STYLE = STATISTICAL options (sheet_interval='none');
However, TAGSETS.EXCELXP generates an XML file, not an Excel file. If you have SAS 9.4 TS1M4+ then I would recommend ODS EXCEL instead.
ods excel file="dt.xlsx" style=statistical options (sheet_interval = 'none');
List of all options for ODS TAGSETS.EXCELXP is here:
https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_help.html
Full example that will generate a single tab:
ods tagsets.excelxp file='C:\_localdata\demo.xls' options(sheet_interval='none');
proc sort data=sashelp.cars out=cars;
by origin;
run;
proc reg data=cars outest=demo tableout;
by origin;
model mpg_city = mpg_highway invoice cylinders;
ods output parameterEstimates=want;
run;
ods tagsets.excelxp close;

ODS PDF - Two columns of output interrupted by one column of output on a single page

I'm trying to create an output for a requestor that wants me to take a preexisting report that comes in two columns on a single page and break it apart on that single page into different subsections, which they want indicated by a new title in the middle of the page where the new subsection begins.
What I have right now is:
ods pdf file=_pdf_ newfile=none startpage=no columns=2 notoc contents=no
style=swsp;
ods text = 'EMPLOYER RENEWAL DATA';
proc report data=renewal_data;
...
run;
ods startpage=now;
ods text='FINANCIAL DATA (FULL PROGRAM YEAR)';
proc report data=financial_data_total;
...
run;
ods startpage=now;
title1 '$ACA_YR_STR. ACADEMIC YEAR DATA';
footnote;
ods text='APPLICANT DATA';
...
run;
What I want is the page to have a section title where the second ods startpage=now is located that treats the entire page as one column, but then returns to two columns for the remainder of the page.
Thanks!
If you have SAS 9.4 (and possibly 9.3), you can use ODS LAYOUT to achieve this pretty easily. You need to create a gridded layout, and then change your title to another ODS TEXT (which you can of course style to be like a title). Titles go with PROCs, not by themselves, so if you actually use title it will appear where the next PROC REPORT goes, not in its own area.
Here's a barebones example that might get you started. See the ODS REGION and ODS LAYOUT documentation for more information. Note, this is something that is in production, but is also in active development, so different versions of SAS (including newer ones) may change how some of this works (though hopefully not break formerly existing functionality, who knows).
ods pdf file="c:\temp\test.pdf" startpage=no newfile=none notoc contents=no
style=swsp;
options obs=10;
ods layout gridded columns=2 rows=3;
ods region row=1 column=1;
ods text = 'CLASS DATA';
proc report data=sashelp.class;
columns name age;
run;
ods region row=1 column=2;
ods text='CAR DATA';
proc report data=sashelp.cars;
columns make model;
run;
ods region column_span=2 row=2 column=1;
ods text='ACROSS THE WHOLE PAGE NOW';
footnote;
ods region row=3 column=1;
ods text='NOT ACROSS WHOLE PAGE FOR THIS PART';
proc report data=sashelp.baseball;
columns name team;
run;
ods layout end;
ods pdf close;

Changing third level nodes in proc report using proc documents

I am trying to make a customize labels in proc report using proc documents. Basically i want the table to have just one level of headers
I move the proc report table out under the Dir and then relabel the table. But even after that, the TOC still have a subnode.
Here is my MWE
/*proc greplay nofs igout=work.gseg; */
/* delete _all_; */
/*run; */
/*quit; */
ods listing close;
ods pdf file="before.pdf" contents=yes ;
ods document name=test(write);
title1 'Using Proc REPORT';
title2 'Simple Report';
* Simple report;
proc report data=test nofs;
columns name sex age;
define name / display;
define sex / display;
define age / display;
run;
ods document close;
ods pdf close;
proc document name=test;
list / levels=all details; run;
/*-- Move output from under folders --*/
move \Report#1\Report#1\Report#1 to ^;run;
/*-- Verify document leaf nodes moved out from under the folders --*/
list / levels=all details; run;
setlabel \Work.test\Report#2 "Custom Heading"; run;
/*-- Delete folders --*/
delete \Report#1/* , \Report#2 */; run;
/*-- Verify folders were deleted --*/
list / levels=all details; run;
/*-- Close Listing Destination --*/
ods listing close;
/*-- Replay output (Print and GPlot to PDF) --*/
ods pdf file="after.pdf" contents=yes ;
replay;
run;
ods pdf close;
quit;
Your proc document looks fine for me. The point is you need to move all higher level objects to first level.
But you will still get the Table * marks in your TOC introduced by proc report.
To remove those marks, first add option contents="" in your proc report, which removes the higher level TOC contents. This is necessary no matter what types of ods destination you want, either rtf or pdf.
proc report data=test nofs contents="";
columns name sex age;
define name / display;
define sex / display;
define age / display;
break before name / contents="" page;
run;
Then you need pdftoc=1 for your ods pdf statement, which limits your TOC to first level.
proc document name=test;
ods pdf file="after.pdf" pdftoc=1 contents=on;
replay;
run;
ods pdf close;
run;
quit;
If you output to rtf, you do not need pdftoc=1 in the 2nd step for ods output, simply like:
proc document name=test;
ods rtf file="after.rtf" toc_data contents=yes;
replay;
run;
ods rtf close;
run;
quit;