SAS ODS RTF - 将 Title/Footnote 嵌入 Table 的最佳选择

SAS ODS RTF - Best option to embed Title/Footnote into Table

正在寻找将 title/footnote 作为 table 的一部分嵌入的建议(见下文 - 更容易复制和粘贴到不同的文档中)

目前探索的选项

1) PROC REPORT - COMPUTE PAGE BEFORE(COMPUTE 不支持对齐选项并且未找到 right-align "page x of y" 文本的任何可靠选项在 title1 中,例如计算和插入 BLANK space。此外,我需要将标题居中对齐)

2) ODS RTF - BODYTITLE 和 BODYTITLE_AUX 选项(显示 title/footnote 作为 body 的一部分但不完全是 table 的一部分 - 不容易select 作为一个 object)

编辑 RTF 可能更容易。

  1. 读取文件并统计cf1{Page
    的出现次数 {\field{*\fldinst { PAGE }}} of {\field{*\fldinst { NUMPAGES
    }}}\cell}

  2. 然后在编写新的内容时再次读取并修改这些行
    文件.

SAS ODS 内联样式指令 ^{PAGEOF} 将在输出文件中生成 Page x of y 输出。由于输出是一个 Word field,您可能需要 Ctrl-A, F9 在打开文档时计算字段值。

RTF 目标在文档的 header 和页脚部分呈现 TITLEFOOTNOTE,因此需要一些技巧来生成 per-table 'titles'和 'footers'。从我作为文档 reader 的角度来看,PAGEOF 的最佳位置是 header 部分,而不是 table header.

的一部分
ods escapechar = '^';
title justify=right '^{PAGEOF}';  

ODS TEXT= 可用于在进行统计报告的 Proc TABULATE 前后添加段落。 ODS TEXT= 将处理内联 ODS 格式化指令(包括 PAGEOF)。有关详细信息,请参阅 SAS® 9.4 Output Delivery System: User’s Guide, Fifth Edition, ODS ESCAPECHAR Statement

ods text='
Narrative before tabular output via ODS TEXT=
^{NEWLINE} Inline styling directives will be processed.
^{NEWLINE} ^{STYLE [color=green]Mix and match}
^{NEWLINE} Let''s see why.
';

ods text='Here you are at ^{STYLE ^{PAGEOF}}';
* This might require Word field computation or print preview to get proper numbers;

取决于目标 STYLE=,例如 ods rtf style=plateau … ODS TEXT 可能有一些大纲或其他样式工件。

如果你是 rtf 硬核,ODS TEXT= 也可以将 rtf 代码直接注入目标流以产生 any rtf 可能的产生。在以下示例中:

  • 旧样式函数^S{attr-name=attr-value}用于强制文本容器为页面宽度的 100%。
  • 当前样式函数^{RAW函数用于引入raw rtf编码。每个 { 的实际 rtf 都是使用 {RAW 引入的。请注意 RAW 是如何嵌套的。

ods text = '^S={outputwidth=100% just=c} ^{RAW \rtf1\ansi\deff0^{RAW \fonttbl^{RAW \f0 Arial;}} 
\qc\f0\fs20\i\b
 This output created with ODS TEXT=\line
 Injecting raw RTF coding\line
 Such as ^{RAW \cf11\ul colored and underlined}\line
 Not for the casual coder.
}'; 

一些程序,例如Proc PRINT有样式选项,例如style(table)=[ … ],其中可以指定pretext=posttext=,这样的文本将在渲染之前在 rtf table 之后——文本不是 table 的一部分,也不会是 'picked up' 单击 Word 的 'table select' 图标( ).此外,不幸的是,不会为 ODS 样式指令处理 pretext= 和 posttext= 值。但是,值 可以 是原始 rtf!

演示内联样式的 PRETEXT 受到尊重:

proc print
  data=sashelp.class (obs=3)
  noobs
  style(table)=[
   pretext='^{STYLE [color=Red]Above 1 ^{NEWLINE}Above 2 - Pretext= is unprocessed ODS directives}' 
   posttext='^{STYLE [color=Green] Below}'
  ]
;
run;

PRETEXT 显示为原始 rtf 通过(当第一个字符是 {

proc print 
  data=sashelp.class (obs=3)
  noobs
  style(table)=[
    pretext='{\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}}
\qc\f0\fs20\i\b This output created with SAS PRETEXT=
\line Injecting raw RTF coding
\line Not for the casual coder.
}'
    posttext='{\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}}
\qc\f0\fs20\i\b This output created with SAS POSTTEXT=
\line Injecting raw RTF coding
\line Not for the casual coder.
}'
  ]
;
run;

Proc TABULATE 没有 style(table) 选项,但是 TABLE 语句有选项:

  • / CAPTION=(在 OPTION ACCESSIBLETABLE; 活动时呈现)
    • 注意:标题值在页面维度容器中呈现,因此如果您的 TABLE 语句在其交叉点中有页面维度,则标题值将被覆盖。
  • / STYLE=[PRETEXT='...' POSTTEXT='...']
    • 与前面提到的相同警告

TABULATE :

  • 具有任何功能,可以让您使用行统计信息对列 header 进行注释(在这种情况下,您的 (N=###) 作为类别值)。汇总要制表的交叉点的预计算步骤将允许您在此处放置统计数据。
  • 提供任何机制来插入跨越 table 的空白行或标签行(例如 Proc REPORT 中的 LINE 语句)

考虑这个带有 accessibletable 的表格示例,用于一些医疗数据。一些变量用于:

  • 分类人口统计(例如性别),
  • 连续测量(例如年龄成本),
  • 关于状态的二进制标志。
data have;
  call streaminit(123);

  do _n_ = 1 to 1e3 - 300 + rand('uniform',600);
    patientId + 1;

    category = ceil(rand('uniform',4));

    age = 69 + floor(rand('uniform',20));
    cost = 500 + floor(rand('uniform',250));

    length sex ;
    sex = substr('MF', 1+rand('uniform',2));

    array flags flag1-flag3; * some flags asserting some medical state is present;
    do over flags; flags = rand('uniform', 4) < _i_; end;

    output;
  end;

  label age = 'Age' cost = 'Cost' sex = 'Sex';
run;

* Precomputation step;
* Use SQL to compute the N= crossings and make that part of a
* new variable that will be in the tabulation column dimension;

proc sql;
  create table for_tabulate as
  select 
    *
    , catx(' ', 'Category', category, '( n =', count(*), ')') 
      as category_counted_columnlabel
  from have
  group by category
  ;
quit;

制表报告

options accessibletable;

proc tabulate data=for_tabulate ;

  class 
    category_counted_columnlabel 
    sex
  /
    missing style=[fontsize=18pt]
  ;

  var age cost flag1-flag3;

  table

    /* row dimension */
    age * ( mean std min max median n*f=8.) * [style=[cellwidth=0.75in]]
    N='Sex' * sex
    cost * ( mean std min max median n*f=8. ) 
    (flag1 - flag3) * mean = '%' * f=percent5.1

    ,

    /* column dimension */
    category_counted_columnlabel = ''

    /

    /* options */
    nocellmerge
    caption = "This is caption text is ^{STYLE [color=green]from Mars}^{NEWLINE}Next line"
  ;

run;

对于 9.4M6 之前的 SAS 版本,您可以将页面维度变量(其值为内联 ODS 程式化文本作为标题)添加到预计算步骤的输出,并在 table 语句中指定该变量.像

,    '^{NEWLINE}title1'  /* SQL step */
  || '^{NEWLINE}title2'
  || '^{NEWLINE}title3'
  || '^{NEWLINE}title4'
  as pagedim_title

/* tabulate step */
class pagedim_title / style = [background=lightgray fontfamily=Arial textalign=right];
table pagedim_title, …, category_counted_columnlabel = '' … ;