Hello,
I am trying to create a report table using PROC REPORT exporting to an rtf file. The table I am getting looks like this:
However I would like to merge the cell labeled "Parameter" with the blank cell above it, so it would look like this:
I've tried playing around with spanrows but no success yet - would appreciate any pointers. Below is my code.
proc report data=summary_table nowindows spacing=1 headline headskip split="|";
columns parameter ('Result' ( t2 ));
define parameter / display left "Parameter"
style(column)=[ font_size=12pt cellwidth=150 asis=on]
style(Header)=[ cellwidth=150 font_weight=bold font_size=12pt asis=on];
define t2 / display center "Hour 01"
style(column)=[ font_size=12pt cellwidth=150 asis=on]
style(column)={just=c}
style(Header)=[ cellwidth=450 font_weight=bold font_size=12pt asis=on];
run;
Thanks in advance!
Maybe @Cynthia_sas knew the answer ?
Hi:
It is harder to span headers vertically in PROC RPORT but it is something you can do in both the header cells and the data cells with the Report Writing Interface (RWI):
Notice how the cells in the Header (for Type) and in the data cells can be accomplished. In PROC REPORT, you can get the values of Type to span rows using the SPANROWS option, but that does not apply to the header cells. And, PROC REPORT will not allow the last column to span rows either, but the RWI method will, as shown above.
Here's the code that I used for this example:
data table3way;
length dmtype durationbi $15;
infile datalines dlm=',' dsd;
input dmtype $ ordvar Durationbi $ Num cMean cSTD LowerCL UpperCL Prob_t;
return;
datalines;
"Type 1",1,"<=10 years",17,76.76,17.85,67.59,85.94,0.7243
"Type 1",2,">10 year",44,75.30,13.06,71.32,79.27,0.7243
"Type 2",1,"<=10 years",47,67.23,22.22,44.44,88.88,0.5584
"Type 2",2,">10 year",35,69.43,33.33,55.55,99.99,0.5584
;
run;
proc sort data=table3way;
by dmtype ordvar durationbi;
run;
** proc report does not span header rows vertically;
proc report data=Table3way spanrows;
column (dmtype) ordvar ('Results' durationbi num cmean cstd lowercl uppercl prob_t);
define dmtype / order "Type" style(column)={vjust=m};
define ordvar / order noprint;
define durationbi / display;
define num / display;
define cmean / display;
define cstd / display;
define lowercl / display;
define uppercl / display;
define prob_t/ order;
run;
** RWI example;
options orientation=portrait;
ods html(id=ht) path='c:\temp\' file="spantest.html";
ods pdf (id=pd) file="c:\temp\spantest.pdf" ;
title 'How to span Header Rows amd Data Rpws with RWI and DATA step';
data _null_;
set table3way end=last;
by dmtype;
if _N_ = 1 then do;
dcl odsout obj();
obj.table_start();
obj.head_start();
** Header row 1;
obj.row_start(type: "Header");
obj.format_cell(text: "Type", row_span:2, column_span: 1, style_attr:"vjust=m color=black backgroundcolor=cxdddddd fontweight=bold");
obj.format_cell(text: "Results", column_span:7, style_attr:"color=black backgroundcolor=cxdddddd fontweight=bold");
obj.row_end();
** Header row 2;
obj.row_start(type: "Header");
obj.format_cell(text: "Durationbi", style_attr:"color=black backgroundcolor=cxdddddd fontweight=bold");
obj.format_cell(text: "num", style_attr:"color=black backgroundcolor=cxdddddd fontweight=bold");
obj.format_cell(text: "cmean", style_attr:"color=black backgroundcolor=cxdddddd fontweight=bold");
obj.format_cell(text: "cstd", style_attr:"color=black backgroundcolor=cxdddddd fontweight=bold");
obj.format_cell(text: "lowercl",style_attr:"color=black backgroundcolor=cxdddddd fontweight=bold");
obj.format_cell(text: "uppercl", style_attr:"color=black backgroundcolor=cxdddddd fontweight=bold");
obj.format_cell(text: "probt",style_attr:"color=black backgroundcolor=cxdddddd fontweight=bold");
obj.row_end();
obj.head_end();
end;
** row for every obs;
** treat dmtype and prob_t differently so they span rows;
obj.row_start();
if first.dmtype then do;
obj.format_cell(data: dmtype,row_span:2, style_attr:"vjust=m fontweight=bold" );
end;
obj.format_cell(data: Durationbi, row_span:1);
obj.format_cell(data: num, row_span:1);
obj.format_cell(data: cmean, row_span:1);
obj.format_cell(data: cstd, row_span:1);
obj.format_cell(data: lowercl, row_span:1);
obj.format_cell(data: uppercl, row_span:1);
if first.dmtype then do;
obj.format_cell(data: prob_t, row_span:2, style_attr:"vjust=m fontweight=bold");
end;
obj.row_end();
if last then do;
obj.table_end();
end;
run;
footnote;title;
ods pdf(id=pd) close;
ods html(id=ht) close;
Cynthia
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.