BookmarkSubscribeRSS Feed
Crystal_F
Quartz | Level 8

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;
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
You do not show all of your ODS statements. Typically, TAGATTR as a style override is used with ODS EXCEL or ODS TAGSETS.EXCELXP. Are you using either of those destinations? I'm curious about why you're using PROTECTSPECIALCHARS=OFF which is most often used when you are inserting raw text into a file like HTML or RTF. Next, you also show listing only options like HEADLINE and HEADSKIP and COLWIDTH which are LISTING only options and ignored by ODS destinations.
In addition, without ALL of your code and without any data, if anyone was inclined to help you they would need to guess at what your work.outputw dataset looked like and then they would need to make up some fake data to test their code.
Is it possible for you to post some sample data and show ALL of your code so we can see your ODS destination of choice. For example, if you are using ODS EXCEL, I would start by getting rid of the LISTING only options.
Cynthia
Crystal_F
Quartz | Level 8

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');
Cynthia_sas
SAS Super FREQ
Hi: Unfortunately, without data, nobody can run or test your code.
Cynthia

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 597 views
  • 3 likes
  • 2 in conversation