SAS Proc报告更改跨变量的标题样式属性

时间:2016-08-04 19:53:55

标签: sas proc-report

SAS Proc报告代码示例如下。我想为跨变量的一个值更改标题背景和前景的颜色。我使用计算块将列背景更改为浅灰色,使用绝对列引用 c4 c5 。如何将 c4 c5 的标题样式属性更改为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;

3 个答案:

答案 0 :(得分:1)

你可以使用格式来做一些接近你所要求的事情,但我不确定它是否可以做你所要求的事情 - 也许是Cynthia Zender对社区的看法。 sas.com可能吗?

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;

这样可以将顶行格式化,但是,实际上并没有得到您要求的行。我不确定它是否可能。

答案 1 :(得分:1)

有可能@ChrisJ指出你可以用CSS样式和第n个孩子选择来做到这一点。不幸的是,由于SAS使用PROC REPORT执行操作的方式,您也有可能无法做到这一点 - 特别是在PROC REPORT <tr> sashelp.cars 内包含的内容标题行,所以nth-child和兄弟选择器是不可能的,因为标题不是彼此的孩子或兄弟姐妹。

以下是一个kludgey版本的示例,以@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 } 为例。

CSS :(保存在驱动器上的.css文件中,说“c:\ temp \ test.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;

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

// my json format
$data={"records":[{"name1":[{"id1":"value","subject","subname"},{"id2":"value","subject2","subname"},{"id3":"value","subject3","subname"},{"id4":"value","subject4","subname"}]},
{"name2":[{"id1":"value","subject","subname"},{"id2":"value","subject2","subname"},{"id3":"value","subject3","subname"},{"id4":"value","subject4","subname"}]}; 

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

不幸的是,我们不能以任何方式识别其中包含“MPG(City)”的单元格,除非知道它们甚至是列数。我们同样无法识别“欧洲”下的细胞,除非知道它们将是哪种细胞。

答案 2 :(得分:0)

尝试在_c语句的末尾添加虚拟列columns,然后添加define&amp; compute继续使用它。

另外,请确保您的颜色名称实际上有效,例如浅 t 灰色无效,无效。

columns ... _c ;
define _c / computed noprint ;
compute _c ;
  call define('_c4_','style','style={background=lightgray}');
  call define('_c5_','style','style={background=lightgray}');
endcomp ;