临床统计分析中的报表经常以如下的样式出现,如果生成这样的表格,可能有很多种方法。现在说一种本人工作中用的方法。
测试数据集就用SASHELP.class.
proc sort data=sashelp.class out=a;by sex name;run;
先定义输出的RTF模板,定义如下(ps,模板如果没定义好,出报告中的某些代码可能不会起作用,具体是哪方面原因还没弄明白)。
proc template;
define style tfl_table;
style body/
leftmargin = 0.5in
rightmargin = 0.5in
topmargin = 1in
bottommargin = 1in;
style table /
frame = hsides
rules = groups
cellpadding = 3pt
cellspacing = 0pt
width = 100%;
style header /
fontfamily = 'Courier New'
asis = off
fontsize = 9pt;
style data /
fontfamily = 'Courier New'
fontsize = 9pt
asis = on;
style TableFooterContainer /
borderbottomcolor = white;
style TitlesAndFooters /
fontfamily = 'Courier New'
textalign = left
fontsize = 10pt;
style systemfooter /
textalign = left
fontfamily = 'Courier New'
fontsize = 9pt;
style NoteContent from Note /
textalign = left
fontsize = 9pt
fontfamily = 'Courier New'
asis = on;
end;
run;
用PROC REPORT 过程步输出RTF的代码如下:
options orientation=portrait nodate nonumber;
ods escapechar='^';
ods rtf file = "d:\test.rtf" style=tfl_table;
footnote "^{super a} : This is done by kongyy";
proc report nowindows data=a;
column sex name ("Sex" header) ("^R'\brdrb\brdrs\brdrw2 'Wonder Treatment" weight height);
define sex /order noprint;
define name /noprint;
define header /'' computed;
define weight / display 'weight' format=8.1 style={just=r};
define height / display 'height' format=8.1 style={just=r};
break before sex /summarize ;
compute header / character length = 20;
if _break_ = 'Sex' then header = Sex;
else header = "^{nbspace 3}"||name;
endcomp;
run;
ods rtf close;
假如要使weight 和 height中的数值小数点位对齐的话,则可使用style来定义。代码如下:
define weight / display 'weight' format=8.1 style={pretext="^R'\tqdec\tx350 '" just=r};
define height / display 'height' format=8.1 style={pretext="^R'\tqdec\tx350 '" just=r};
除了以上方法产生缩进RTF外,还可以用^w产生空格的效果, ^ 这个为自定义的ods escapechar.
compute header / character length = 20;
if _break_ = 'Sex' then header = Sex;
else header = "^w^w^w^w"||name;
endcomp;
好了,以上就是我想分享的,更多的输出格式控制技巧,以后有空再探索。谢谢。