我想要一个包含目录的RTF文件,但我也想要标题和脚注
与目录在同一页面上。下面的代码将生成一个RTF文件,其中包含每个proc report
表只有一个TOC行的目录:
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;
如何制作标题和脚注,以便在第一页上显示目录以及文档的其余部分?
答案 0 :(得分:0)
这是一个黑客攻击,但它是我能找到的唯一方法。问题的关键在于我们只是要改变SAS使用某些SAS编程输出的RTF文件。关键在这里我在文件中读取,拉出第一个页眉和页脚信息,然后在文档的开头插入一个副本并输出到一个单独的文件:
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;
当然,还有SAS自动放入的日期和页码,我不想要,所以我在创建原始RTF文件之前更新了该选项。以下是所有代码,以防将来帮助某人:
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;