2

我想要一个带有目录的 RTF 文件,但我还想要与目录在同一页面上的标题和脚注。下面的代码将生成一个带有目录的 RTF 文件,每个表只有一个 TOC 行proc report

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;

如何使标题和脚注与目录以及文档的其余部分一起出现在第一页上?

4

1 回答 1

0

这是一个 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;
于 2015-11-16T19:44:10.300 回答