My base code is this:
Additionally, I would like to put a spanning header beneath make and model that says "Make and Model". How can I do this?
You want this ?
%let mypath=c:\temp;
ods rtf file="&mypath.\odsr_column_span.rtf" style=journal;
title "Complex Column Spanning";
data _null_;
set sashelp.cars(keep= make model drivetrain) end=last;
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: "Parameter", column_span:2,style_attr:"color=black backgroundcolor=white fontweight=bold fontstyle=roman borderbottomcolor=black borderbottomwidth=2");
obj.format_cell(text: "Drive Train", row_span:3, style_attr:"color=black backgroundcolor=white vjust=b fontweight=bold fontstyle=roman");
obj.row_end();
** Header row 2;
obj.row_start(type:"Header");
obj.format_cell(text: "Make", column_span:1, style_attr:"color=black backgroundcolor=white fontweight=bold fontstyle=roman");
obj.format_cell(text: "Model", column_span:1, style_attr:"color=black backgroundcolor=white fontweight=bold fontstyle=roman");
obj.row_end();
** Header row 3;
obj.row_start(type: "Header");
obj.format_cell(text: "Make and Model", column_span:2, style_attr:"color=black backgroundcolor=white fontweight=bold fontstyle=roman bordertopcolor=black bordertopwidth=2");
obj.row_end();
obj.head_end();
end;
** row for every obs;
obj.row_start();
obj.format_cell(data: make, row_span:1);
obj.format_cell(data: model, row_span:1);
obj.format_cell(data: drivetrain, row_span:1);
obj.row_end();
if last then do;
obj.table_end();
end;
run;
ods rtf close;
title; footnote;
Another easy and simple way is using this:
ods rtf file='c:\temp\temp.rtf' style=journal;
ods escapechar='~';
proc report data=sashelp.cars(obs=20) nowd style(header)={fontstyle=roman};
columns ('~S={borderbottomcolor=black borderbottomwidth=2}Parameter'
('~S={borderbottomcolor=black borderbottomwidth=2}Make Model'
('Make and Model' make model))) ('Drive Train' drivetrain);
define make/'' style={just=c};
define model/'' style={just=c};
define drivetrain/'' style={just=c};
run;
ods rtf close;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.