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');
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.