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?
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;
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;
I'd suggest using proc tabulate instead, you can apply styles within the procedure rather than mess with the template code.
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;
OK Thanks you!!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.