The SAS Output Delivery System and reporting techniques

Proc freq ods output

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Proc freq ods output

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;


Accepted Solutions
Solution
‎01-14-2013 04:08 PM
SAS Super FREQ
Posts: 8,745

Re: Proc freq ods output

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


All Replies
Super User
Posts: 17,963

Re: Proc freq ods output

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

Solution
‎01-14-2013 04:08 PM
SAS Super FREQ
Posts: 8,745

Re: Proc freq ods output

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;

New Contributor
Posts: 2

Re: Proc freq ods output

OK Thanks you!!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 445 views
  • 0 likes
  • 3 in conversation