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;
Related
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;
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;
I am trying to prepare a report in Excel using ODS Excel in SAS. The report contains two sheets with three tables place side by side. I used Panelcol option but it is not available in ODS Excel. Also, the Start_at= option does not seem to be working?
Is there anyway it can be done in ODS Excel? Please let me know.
Any help will be very much appreciated.
Thank you,
Shankar
Shankar:
The ODS EXCEL docs for 9.4 state the start_at= options can not be changed mid-sheet. Link
(START_AT='string') specifies a starting cell for the report. The
default is to start at column 1 and row 1. Default 1,1 Tip This option
cannot be changed in the middle of a sheet. Example ods excel
options(start_at="2,2");
So this example does not work as you expect. The first start_at is honored, and subsequent output on the same page is stacked while still honoring the first start at column.
ods _all_ close;
ods excel file='%temp%\3-tables-in-first-tab-sample.xlsx'
options (sheet_interval='none')
;
ods excel options (start_at="2,2");
* top of output is upper left corner;
proc print noobs data=sashelp.class(keep=name age);run;
* top of output is to the right and down three rows from the first output;
ods excel options (start_at="5,5");
proc print noobs data=sashelp.class(keep=name weight height);run;
ods excel options (start_at="1,9");
proc print noobs data=sashelp.class(keep=name sex);run;
ods excel close;
One way to put multiple tables together is to create a faux table that appends data in a sidewise manner.
Example:
%macro RHS_append (out=, data=);
%if not %sysfunc(exist(&out)) %then %do;
data &out; set &data; run;
%return;
%end;
%local nout names labels;
proc contents noprint data=&out out=outvar(keep=name varnum label);
proc contents noprint data=&data out=datavar(keep=name varnum label);
proc sql noprint; select count(*) into :nout trimmed from outvar;
select
cats(name,'=v',&nout+varnum+1)
, case
when label=''
then cats('v',&nout+varnum+1,'=',quote(trim(name)))
else ''
end
into
:names separated by ' '
, :labels separated by ' '
from datavar order by varnum
;
create table gap (v%eval(&nout+1) char(1) label='a0'x);
quit;
data &out;
merge &out gap &data(rename=(&names)); %* rare use of merge without by;
label &labels;
run;
%mend;
options mprint;
proc delete data=foo;
run;
%RHS_append (out=foo, data=sashelp.class);
%RHS_append (out=foo, data=sashelp.gas);
%RHS_append (out=foo, data=sashelp.cars);
ods excel file='%temp%\3-tables-in-first-tab-sample.xlsx';
proc print label data=foo;
run;
ods excel close;
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;
I would like an RTF file with a table of contents, but I also want the titles and footnotes
on the same page as the table of contents. Here is code that will produce an RTF file with a table of contents that only has one TOC line per proc report table:
data testdata;
input letters $ numbers;
cards;
A 1
B 2
C 3
;
run;
data testdata;
set testdata;
dummy=1;
run;
ods rtf FILE="test.rtf" startpage=no style=analysis CONTENTS=YES toc_data;
ods escapechar="^";
title1 j=l "This title should be on every page" j=r "Page ^{pageof}";
title2 j=l "(even the first one)";
footnote1 "This footnote should be on every page, too";
ods rtf text="{\pard\page\par}";
ods proclabel 'Test Data';
proc report nowd data=testdata contents='';
column dummy ('Test Data' letters numbers);
define dummy / group noprint;
define letters / "Letters";
define numbers / "Numbers";
break before dummy / contents='' page;
run;
ods rtf close;
How can I make it so that the titles and footnote appear on the first page with the table of contents as well as the rest of the document?
This is a hack, but it's the only way I could find to make it work. The crux of it is that we are just going to alter the RTF file that is output by SAS using some SAS programming. The key is here where I read in the file, pull out the first header and footer information, then insert a copy at the beginning of the document and output to a separate file:
data edit hf;
infile "test.rtf" dlm='09'x dsd lrecl=32767 missover;
format var $200.;
input var $;
output edit;
retain head fhead ffoot 0;
if index(var,'{\header')>0 and fhead=0 then head = 1;
if head = 1 and fhead=0 then output hf;
if index(var,'{\footer')>0 then ffoot=1;
if index(var,'\pard}}\trowd\trkeep\trql')>0 and ffoot=1 then fhead=1;
keep var;
run;
data edit1 edit2;
set edit;
retain start 0;
if index(var,'\widowctrl\')>0 then start=1;
if start=0 then output edit1;
else output edit2;
keep var;
run;
data out;
set edit1 hf edit2;
run;
data _null_;
set edit1 hf edit2;
file 'test1.rtf';
put var;
run;
Of course, there was also the date and page number that SAS puts in there automatically that I didn't want, so I updated that option before creating the original RTF file. Here is all the code together in case it helps someone in the future:
data testdata;
input letters $ numbers;
cards;
A 1
B 2
C 3
;
run;
data testdata;
set testdata;
dummy=1;
run;
options nodate nonumber;
ods rtf FILE="test.rtf" startpage=no style=analysis CONTENTS=YES toc_data;
ods escapechar="^";
title1 j=l "This title should be on every page" j=r "Page ^{pageof}";
title2 j=l "(even the first one)";
footnote1 "This footnote should be on every page, too";
ods rtf text="{\pard\page\par}";
ods proclabel 'Test Data';
proc report nowd data=testdata contents='';
column dummy ('Test Data' letters numbers);
define dummy / group noprint;
define letters / "Letters";
define numbers / "Numbers";
break before dummy / contents='' page;
run;
ods rtf close;
data edit hf;
infile "test.rtf" dlm='09'x dsd lrecl=32767 missover;
format var $200.;
input var $;
output edit;
retain head fhead ffoot 0;
if index(var,'{\header')>0 and fhead=0 then head = 1;
if head = 1 and fhead=0 then output hf;
if index(var,'{\footer')>0 then ffoot=1;
if index(var,'\pard}}\trowd\trkeep\trql')>0 and ffoot=1 then fhead=1;
keep var;
run;
data edit1 edit2;
set edit;
retain start 0;
if index(var,'\widowctrl\')>0 then start=1;
if start=0 then output edit1;
else output edit2;
keep var;
run;
data out;
set edit1 hf edit2;
run;
data _null_;
set edit1 hf edit2;
file 'test1.rtf';
put var;
run;