proc报告跨越标题颜色

时间:2016-02-05 08:06:19

标签: sas

数据集in包含4列col1-col4。我正在尝试创建一个输出,将4列分成两部分。

在下面的代码中,通过添加假变量blank,我可以在 A部分 B部分之间添加一个空列。

options missing='';
proc report data=in missing
style(header)=[background=steelblue];
column ('Part A' col1 col2) blank ('Part B' col3 col4);
define blank/computed ' ' style=[background=white];
define col1 / display style[background=tan];
...
compute blank;
blank = .;
call define(_col_,'style','style={background=white borderbottomcolor=white}');
endcomp;
run;

问题是我需要

  1. 两种不同的颜色,用于生成标题和“原始”标题。

  2. 两个生成标题之间的列应全为白色。

  3. 但是代码无法达到第二目的。

    当前输出看起来像

    1st row  ------      Part A        Part B   (steelblue for entire row)
    
    2nd row  ------    col1 col2      col3 col4 (col1-col4 are tan, the column between col2 and col3 and white)
    

    但是所需的输出是

    1st row  ------      Part A        Part B   (steelblue for Part A & B, but the column between them should be white)
    
    2nd row  ------    col1 col2      col3 col4 (col1-col4 are tan, the column between col2 and col3 and white)
    

    我找到了这篇文章,但我甚至无法复制Cynthia的输出。 proc格式似乎不起作用。

    Proc Report - Coloring for Spanning Headers

    这在excel中相当容易 - 只需插入一个新的空列而不填充该列。我怎么能在SAS中做到这一点?

2 个答案:

答案 0 :(得分:1)

你没有提到ODS目的地。这适用于HTML和PDF(有点)。 我认为关键是假设它实际上做你想要的是使用' a0' x ascii非破坏空间。但这还没有经过充分测试。

title;
options missing='';
proc format;
  value $color
      'a0'x = 'white'
      other='steelblue'
      ;
proc report data=sashelp.class missing
   style(header)=[background=$color. borderbottomcolor=$color.];
   column ('Part A' name sex) ('a0'x blank) ('Part B' age weight height);
   define _all_ / display style=[background=tan];

   define blank / computed 'a0'x 
      style=[background=white borderbottomcolor=white] 
      style(header)=[background=white borderbottomcolor=white];

   compute blank / char length=1;
      blank = ' ';
      call define(_col_,'style','style={background=white borderbottomcolor=white}');
      endcomp;
   run;

enter image description here

答案 1 :(得分:0)

Cynthia发布的代码包含语法错误(proc报告中的标题+ ;行上缺少style(header)

通过修复,这适用于我(SAS 9.3 AIX):

proc format;
     value $color
          'REPORT' = '#9999FF'
          'Australia' = '#FF6600'
          'States' = 'pink'
          'Wombat' = 'lightgreen'
          other = 'lightblue';

     value $altclr
          'REPORT' = '#9999FF'
          'Australia' = '#FF6600'
          'States', 'Height', 'Weight' = 'pink'
          'Wombat', 'Name', 'Age', 'Sex' = 'lightgreen'
          other = 'lightblue';
run;

ods listing close;
ods tagsets.excelxp file = "%SYSFUNC(pathname(work))./Test.xml"
    options ( embedded_titles='yes') style = sansprinter;

title 'All Headers Different Colors Based on Formats';
proc report data = sashelp.class(obs=3) nowd
   style(header) = { background = $color. font_size= 10pt };
   column ('REPORT'('Australia' ('Wombat' name age sex )('States' height weight)));
run;

title 'Some Headers Same Colors Based on Formats (one header diff)';
proc report data = sashelp.class(obs=3) nowd
   style(header) = { background = $altclr. font_size= 10pt };
   column ('REPORT'('Australia' ('Wombat' name age sex )('States' height weight)));
   define name / 'Name';
   define age / 'Age';
   define sex / 'Sex';
   define height / 'Height';
   define weight / 'Weight'  style(header)={background=lightyellow};
run;

ods _all_ close;