首页 > 解决方案 > 使用 proc 报告在 RTF 输出中水平合并单元格

问题描述

我正在尝试在数据中的每个组上方创建一个摘要行。我有两个问题:

  1. 如何在摘要行中水平合并前 2 个单元格(下面的红色单元格)。
  2. 如何删除 Sex 列中重复的 F 和 M(目前我可以通过仅将这些单元格的文本颜色更改为白色来解决此问题,但希望有更好的方法)

输出是一个 RTF 文件,我使用的是 SAS 9.4 - 桌面版本。

这可以使用 proc 报告吗?

代码:

options missing=' ';
proc report data=sashelp.class nowd;
    columns sex name age weight;
    define sex / order;
    break before sex / summarize;
run;

在此处输入图像描述

标签: sasproc-report

解决方案


我认为您不能合并汇总行中的单元格。

compute块的一些技巧,call define可以改变单元格的值和外观。

例如(对于较小的图像只有 J 名称):

proc report data=sashelp.class nowd;
    where name =: 'J';

    columns sex name age weight;

    define sex / order;
    define age / sum;
    define weight / sum;
    break before sex / summarize style=[verticalalign=bottom];

    compute name;
      * the specification of / order for sex sets up conditions in the name value
      * that can be leveraged in the compute block;

      if name = ' ' then do; 
        * a blank name means the current row the compute is acting on 
        * is the summarization row;

        * uncomment if stat is not obvious or stated in title;
        * name = 'SUM';  

        * 'hide' border for appearance of merged cell;
        call define (1, 'style', 'style=[fontsize=18pt borderrightcolor=white]');
      end;
      else do;
        * a non-blank name means one of the detail rows is being processed;
        * blank out the value in the sex column of the detail rows;
        * the value assignment can only be applied to current column or those
        * to the left;
        sex = ' ';
      end;
    endcomp;

    compute after sex;
      * if you want more visual separation add a blank line;
      * line ' ';
    endcomp;
run;

在此处输入图像描述


推荐阅读