BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jack_nicholson
Calcite | Level 5

Hi,

I try to create a table from the proc freq, but I would like a white background for the 'Total' cells and keep the column and  row label with a blue background.

Someone now how can I do that?

sas output.jpg

Here is my code to get the previous table

proc template;

define crosstabs Base.Freq.CrossTabFreqs;

row_var_style=rowheader {backgroundcolor=white VERTICALALIGN=MIDDLE font_weight=bold};

col_var_style=header {backgroundcolor=white VERTICALALIGN=MIDDLE font_weight=bold};

define header tableof;

end;

define header rowsheader;

text _row_label_ / _row_label_ ^= ' ' ;

text _row_name_ ;

style={background=CX99CCFF VERTICALALIGN=MIDDLE font_weight=bold};

end;

define header colsheader;

text _col_label_ / _col_label_ ^= ' ';

text _col_name_;

style={background=CX99CCFF VERTICALALIGN=MIDDLE font_weight=bold};

end;

cols_header=colsheader;

rows_header=rowsheader;

header tableof;

end;

run;

ods rtf file;

ODS NOPROCTITLE;

options validvarname=ANY;

proc freq DATA=ALL(RENAME=(Sex_var="Sexe"n Age_var="Age"n)) ORDER=DATA;

TABLE "Sexe"n*"Age"n / nopercent nocol norow;

label "Sexe"n=;

label "Age"n=;

run;

ods rtf close;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  I agree. I think it is easier to use either PROC TABULATE or PROC REPORT than to change the template for PROC FREQ. Given that there already is an investment in PROC FREQ, the OP would have to define a specific header section in order to apply style changes to the header. PROC PRINT, PROC REPORT and PROC TABULATE already have those controls in place.

See code below using SASHELP.CLASS.

cynthia

proc format;
  value agef 11-12 = 'Pre-teens'
             13-16 = 'Teens';
run;

  

ods rtf file='c:\temp\tabulate_report.rtf';
proc tabulate data=sashelp.class f=3.0;
title 'Use Tabulate instead of PROC FREQ';
  class age sex /
    style={background=CX99CCFF
           font_weight=bold};
  classlev age sex/
     style={background=white foreground=black font_weight=bold};
  table sex=' ' all='Total',
        age*n=' ' all=' '*n='Total' /
        box={label='Sexe'  s={background=cx99ccff}};
  format age agef.;
  keyword all n/
    style={background=CX99CCFF
           font_weight=bold};
run;

 

** make length of SEX variable longer;

** to use TOTAL label at report summary;

** because otherwise, SEX variable is a length of $1;

data class;
  length sex $8;
  set sashelp.class;
run;

   

proc report data=class nowd
  style(Header)={background=CX99CCFF
                 font_weight=bold}
  style(summary)={background=CX99CCFF font_style=roman font_weight=bold};
  title 'Use REPORT instead of PROC FREQ';
  column ('Sexe' sex) ('Age' age,n ('Total' age=agetot));
  define sex / group ' ';
  define age / across ' ' f=agef.
         style(header)={background=white
                        font_weight=bold};
  define n / ' ';
  define agetot / ' ';
  rbreak after / summarize;
  compute after;
     sex='Total';
     call define('_c2_','style','style={background=white}');
     call define('_c3_','style','style={background=white}');
     call define('_c4_','style','style={background=white}');
  endcomp;
run;
ods rtf close;

View solution in original post

3 REPLIES 3
Reeza
Super User

I'd suggest using proc tabulate instead, you can apply styles within the procedure rather than mess with the template code.

http://www2.sas.com/proceedings/sugi29/085-29.pdf

Cynthia_sas
SAS Super FREQ

Hi:

  I agree. I think it is easier to use either PROC TABULATE or PROC REPORT than to change the template for PROC FREQ. Given that there already is an investment in PROC FREQ, the OP would have to define a specific header section in order to apply style changes to the header. PROC PRINT, PROC REPORT and PROC TABULATE already have those controls in place.

See code below using SASHELP.CLASS.

cynthia

proc format;
  value agef 11-12 = 'Pre-teens'
             13-16 = 'Teens';
run;

  

ods rtf file='c:\temp\tabulate_report.rtf';
proc tabulate data=sashelp.class f=3.0;
title 'Use Tabulate instead of PROC FREQ';
  class age sex /
    style={background=CX99CCFF
           font_weight=bold};
  classlev age sex/
     style={background=white foreground=black font_weight=bold};
  table sex=' ' all='Total',
        age*n=' ' all=' '*n='Total' /
        box={label='Sexe'  s={background=cx99ccff}};
  format age agef.;
  keyword all n/
    style={background=CX99CCFF
           font_weight=bold};
run;

 

** make length of SEX variable longer;

** to use TOTAL label at report summary;

** because otherwise, SEX variable is a length of $1;

data class;
  length sex $8;
  set sashelp.class;
run;

   

proc report data=class nowd
  style(Header)={background=CX99CCFF
                 font_weight=bold}
  style(summary)={background=CX99CCFF font_style=roman font_weight=bold};
  title 'Use REPORT instead of PROC FREQ';
  column ('Sexe' sex) ('Age' age,n ('Total' age=agetot));
  define sex / group ' ';
  define age / across ' ' f=agef.
         style(header)={background=white
                        font_weight=bold};
  define n / ' ';
  define agetot / ' ';
  rbreak after / summarize;
  compute after;
     sex='Total';
     call define('_c2_','style','style={background=white}');
     call define('_c3_','style','style={background=white}');
     call define('_c4_','style','style={background=white}');
  endcomp;
run;
ods rtf close;

jack_nicholson
Calcite | Level 5

OK Thanks you!!

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
  • 1995 views
  • 0 likes
  • 3 in conversation