Hi Cynthia, Thank you for your comments. Sometimes I use similar codes generating rtf and excel. That's the reason you still see part of the codes for rtf. Below is the complete version of my code. %macro exportOutput(cohort, sheetname);
ods excel file="/Volumes/data/Output/Table_&cohort..xlsx" options(sheet_name=&sheetname.);
title "Table1. Baseline Characteristics by Study Cohorts";
proc report data=outputw style(report)={just=left} colwidth=6
style(header)={just=center protectspecialchars=off font_weight=BOLD background=white}
headline headskip split="/" missing;
column group ('Characteristics' vardesc) (' ' var_val)
("UC Overall"
("N" col1_cohort1) ("%" col2_cohort1) )
("UC Moderate to Severe"
("N" col1_cohort2) ("%" col2_cohort2) )
("UC Trial Similar"
("N" col1_cohort3) ("%" col2_cohort3) )
("General Population"
("N" col1_cohort4) ("%" col2_cohort4) )
;
define group /group noprint order=data;
define vardesc /group ' ' order=data style=[just=l];
define var_val / display ' ' order=data style(column)={width=1 in just=l};
define col1_cohort1 /display ' ' format=comma10. style(column)={cellwidth=0.5in just=c };
define col2_cohort1 /display ' ' format=comma5.2 style(column)={cellwidth=0.5in just=c };
define col1_cohort2 /display ' ' format=comma10. style(column)={cellwidth=0.5in just=c };
define col2_cohort2 /display ' ' format=comma5.2 style(column)={cellwidth=0.5in just=c};
define col1_cohort3 /display ' ' format=comma10. style(column)={cellwidth=0.5in just=c };
define col2_cohort3 /display ' ' format=comma5.2 style(column)={cellwidth=0.5in just=c };
define col1_cohort4 /display ' ' format=comma10. style(column)={cellwidth=0.5in just=c };
define col2_cohort4 /display ' ' format=comma5.2 style(column)={cellwidth=0.5in just=c};
compute before group/ style=[just=l font_weight=bold];
line @1 group group.;
endcomp;
compute var_val;
call define(_col_,"style","style={leftmargin=.15in font_weight=medium}");
endcomp;
compute col1_cohort1;
if var_val in ('Mean (SD)') then call define(_col_,"format","format=comma5.2");
/* if var_val in ('Mean (SD)') then call define(_col_,'style','style=[TAGATTR="format:#,##0.00"]'); */
endcomp;
compute col1_cohort2;
if var_val in ('Mean (SD)') then call define(_col_,"format","format=comma5.2");
/* if var_val in ('Mean (SD)') then call define(_col_,'style','style=[TAGATTR="format:#,##0.00"]'); */
endcomp;
compute col1_cohort3;
if var_val in ('Mean (SD)') then call define(_col_,"format","format=comma5.2");
/* if var_val in ('Mean (SD)') then call define(_col_,'style','style=[TAGATTR="format:#,##0.00"]'); */
endcomp;
compute col1_cohort4;
if var_val in ('Mean (SD)') then call define(_col_,"format","format=comma5.2");
/* if var_val in ('Mean (SD)') then call define(_col_,'style','style=[TAGATTR="format:#,##0.00"]'); */
endcomp;
run;
/* ods rtf close; */
/* ods listing; */
title;
ods excel close;
%mend exportOutput;
%exportOutput(Cohorts, 'Table 1-Demographic');
... View more