1

下面是一个示例 SAS Proc 报告代码。我想为 cross 变量的一个值更改标题背景和前景的颜色。我使用计算块使用绝对列引用c4c5将列背景更改为浅灰色。如何将c4c5的标题样式属性更改为 background=gainboro 和foreground=black?

data test;
length name $ 10 disease $ 10.;
infile datalines dsd;
input name $ disease cases rate;
datalines;
State,Fever,4847,25.16
State,Cold,25632,131.5
State,Flu,103825,535.82
Lincoln,Fever,3920,44.17
Lincoln,Cold,16913,190.18
Lincoln,Flu,62965,735.39
Washington,Fever,827,56.56
Washington,Cold,3609,234.26
Washington,Flu,16610,1078.8
Kings,Fever,1026,37.45
Kings,Cold,4984,181.85
Kings,Flu,18388,694.33
Sussex,Fever,1411,78.38
Sussex,Cold,5515,300.46
Sussex,Flu,13881,813.11
Queens,Fever,616,26.03
Queens,Cold,2496,107.75
Queens,Flu,12518,558.09
;
run;


proc report data=test nowd headline headskip
STYLE(Header)={background=charcoal foreground=white }
style(column)={background=gray foreground=black}
style(report)=[rules=rows bordercolor=white];
columns (name disease,(cases rate));
define name/group order=data 'County' style(column)={background=lighttgray} style(header)=[bordertopcolor=gainsboro background=gainsboro foreground=black];
define disease/across '' order=data  ;
define cases/'Cases' format=comma9. ;
define rate/'Rate' format=comma12.1 ;
compute cases;
    call define('_c4_','style','style={background=lighttgray}');
    call define('_c5_','style','style={background=lighttgray}');
endcomp;
run;
quit;
run;
4

3 回答 3

1

您可以使用格式来做一些接近您所要求的事情,但我不确定是否有可能做您所要求的 - 也许 community.sas.com 上的 Cynthia Zender 可能?

data test;
length name $ 10 disease $ 10.;
infile datalines dsd;
input name $ disease cases rate;
datalines;
State,Fever,4847,25.16
State,Cold,25632,131.5
State,Flu,103825,535.82
Lincoln,Fever,3920,44.17
Lincoln,Cold,16913,190.18
Lincoln,Flu,62965,735.39
Washington,Fever,827,56.56
Washington,Cold,3609,234.26
Washington,Flu,16610,1078.8
Kings,Fever,1026,37.45
Kings,Cold,4984,181.85
Kings,Flu,18388,694.33
Sussex,Fever,1411,78.38
Sussex,Cold,5515,300.46
Sussex,Flu,13881,813.11
Queens,Fever,616,26.03
Queens,Cold,2496,107.75
Queens,Flu,12518,558.09
;
run;


proc format;
  value $headerbackf
  'Cold' = 'gainsboro'
  other  = 'charcoal';
  value $headerforef
  'Cold' = 'black'
  other  = 'white'
  ;
quit;

proc report data=test nowd headline headskip
STYLE(Header)={background=charcoal foreground=white }
style(column)={background=gray foreground=black}
style(report)=[rules=rows bordercolor=white];
columns (name disease,(cases rate));
define name/group order=data 'County' style(column)={background=lightgray} style(header)=[bordertopcolor=gainsboro background=gainsboro foreground=black];
define disease/across '' order=data style(header)={background=$HEADERBACKF. foreground=$HEADERFOREF.};
define cases/'Cases' format=comma9. style(header)=inherit;
define rate/'Rate' format=comma12.1 ;
compute cases;
    call define('_c4_','style','style={background=lighttgray}');
    call define('_c5_','style','style={background=lighttgray}');
endcomp;
run;

这会格式化第一行,但实际上并没有得到您要求的行。我不确定有没有可能。

于 2016-08-04T21:48:36.307 回答
1

正如@ChrisJ 指出的那样,您可能可以使用 CSS 样式和第 n 个子项选择来做到这一点。不幸的是,由于 SAS 的处理方式,您也有可能无法做到PROC REPORT- 特别是在包括PROC REPORT标题行在内的所有内容都被推到<tr>s内时,因此由于标题不是子级或兄弟级,因此 nth-child 和兄弟选择器是不可能的彼此的。

这是一个杂乱无章的版本的例子,sashelp.cars作为一个例子。

CSS:(保存在驱动器某处的 .css 文件中,例如“c:\temp\test.css”):

@import 'base.css';

/* Red the second (really third) column header value */
.table thead tr:nth-child(2) th:nth-child(3)  {
    color:red
}

/* Yellow background for the mpg headers under Europe */
.table thead tr:nth-child(3) th:nth-child(4),
.table thead tr:nth-child(3) th:nth-child(5)
{
    background-color:yellow
}

/* Green the mpg-city values */
.table thead tr:nth-child(3) th:nth-child(even) {
    color:green
}

SAS程序:(假设上面保存的CSS文件)

ods html file='example.html' cssstyle='c:\temp\test.css'(html);
ods pdf file='example.pdf' cssstyle='c:\temp\test.css'(print);
proc sort data=sashelp.cars out=cars; by origin;
run;
proc report data=cars nowd;
  columns type origin,(mpg_city mpg_highway);
  define origin/across;
  define type/group;
  define mpg_City / analysis mean;
  define mpg_highway / analysis mean;    
run;

ods _all_ close;

这部分基于 Kevin Smith 的Unveiling the power of Cascading Style Sheets (CSS) in ODS

不幸的是,我们无法以任何方式识别其中包含“MPG(City)”的单元格,除非知道它们将是偶数列号。我们同样无法识别“欧洲”下的单元格,除非知道这些单元格将是什么单元格。

于 2016-08-05T17:01:46.163 回答
0

尝试在语句_c的末尾添加一个虚拟列,并添加一个&来配合它。columnsdefinecompute

另外,请确保您的颜色名称实际上是有效的,例如 light t gray 是无效的并且不会起作用。

列 ... _c ;
定义 _c / 计算的 noprint ;
计算_c;
  调用define('_c4_','style','style={background=lightgray}');
  调用define('_c5_','style','style={background=lightgray}');
结束压缩;
于 2016-08-04T20:33:48.010 回答