Hi everyone,
I'm having a problem resetting the decimal places to 2 for means with codes as below. Results on mean weren't always displayed as expected (compute for col1_cohort for example)
e.g.2.777,52.27... The statements commented out didn't work neither.
Is there anyone that could help me fix the problem? Many thanks!
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;
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');
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.