这是一个 hack,但这是我能找到使其工作的唯一方法。关键在于我们将使用一些 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;