Below is a test program that creates different styles 'border1' and 'border2' and then writes output using PROC TABULATE to an ODS HTML destination.
In the ODS HTML statement, I can specify style=borders1 or style=borders2 and verify the table looks different.
What if I want two tables in the same ODS HTML output, one in one style and one in the other?
Is there a way to switch styles after the first table? Or a way to change the ODS HTML specification, but have the second output appended to the first instead of overwriting it?
________________________________________
%let progname = %sysfunc(scan( %sysfunc(scan(%sysFunc( compress(&sysProcessName,%str(%")) ), -1, '\')), 1, '.'));
%let dirname = %sysfunc(scan( %sysfunc(scan(%sysFunc( compress(&sysProcessName,%str(%")) ), -2, '\')), 1, '.'));
proc template;
define style borders1;
parent=styles.default;
style Table from Output /
cellspacing=0
cellpadding=8pt
frame=void
RULES=all
borderwidth=1
borderspacing=0
bordercollapse=collapse
bordercolor=GRAYBB
;
style Header from HeadersAndFooters /
/* Blend headers */
background=color_list('bgA');
style Data From Data /
/* Blend data background */
background=color_list('bgA')
;
end;
define style borders2;
parent=styles.default;
style Table from Output /
cellspacing=0
cellpadding=24pt
frame=void
RULES=all
borderwidth=1
borderspacing=0
bordercollapse=collapse
bordercolor=RED
;
style Header from HeadersAndFooters /
/* Blend headers */
background=color_list('bgA');
style Data From Data /
/* Blend data background */
background=color_list('bgA')
;
end;
run;
ods html file="&progname..htm" (title="&progname") style=borders2 ;
options nocenter;
title1 "%bquote(%sysfunc(getoption(sysin)) - &sysday &sysdate &systime )";
data a;
do y = 1 to 3;
do x = 1 to 5;
z +1;
output;
end;
end;
run;
proc tabulate data=a format=best.;
class x y;
var z;
table sum*z, y, x;
run;
/*
TEMPLATE Procedure: Creating a Style Template
Detailed Information for All Style Attributes
*/
HI:
Proc TABULATE, Proc REPORT, Proc PRINT do NOT have table templates like the other procedures (FREQ, MEANS, GLM, REG, etc all have TABLE templates). TABULATE, REPORT and PRINT are impacted by the STYLE= overrides in the procedure syntax. They will use a style template and you can change a style in "mid stream" to get a different style template used with each tabulate step (see attached screen shot and code). But you cannot point the same tabulate step to 2 different style templates. The STYLE= override statements in a TABULATE step override what is in 1 and only 1 style definition.
cynthia
You can add the style to the proc statement for most report procedures:
proc tabulate data=dataset style=borders1;
<class var and table statements>
run;
proc tabulate data=dataset style=borders2;
<class var and table statements>
run;
I believe, though haven't tried it, that with tabulate you can add style per table
proc tabulate data=dataset;
<class var statements>
table class1, class2*var*n
/ style=[style=borders1];
table class1, class2*var*sum
/ style=[style=borders2];
run;
Thanks for that suggestion. If I try it, though, it doesn't seem to have the desired effect at all.
I also tried appending to the html file as well, following the article below, with the different styles on the ODS HTML statements again, and while it appended to the HTML file, it didn't switch styles as intended.
I suspect there is a really simple way of doing this but it's just too hard to figure out.
Usage Note 23660: How can I append to an ODS HTML output file?
Another approach might be
ODS HTML style = <style choice>;
just before the proc. Note this would be separate from the destination.
Also with HTML, I've not had good luck in general with File= and instead use Path= and body= but that may just be interactions with my other options.
I think you'll need to modify the template for proc tabulate rather than the style template, and it would have be in between the procs.
Changing the style option of the HTML file didn't seem to work in my quick tests.
HI:
Proc TABULATE, Proc REPORT, Proc PRINT do NOT have table templates like the other procedures (FREQ, MEANS, GLM, REG, etc all have TABLE templates). TABULATE, REPORT and PRINT are impacted by the STYLE= overrides in the procedure syntax. They will use a style template and you can change a style in "mid stream" to get a different style template used with each tabulate step (see attached screen shot and code). But you cannot point the same tabulate step to 2 different style templates. The STYLE= override statements in a TABULATE step override what is in 1 and only 1 style definition.
cynthia
Does that work in HTML3 only, it didn't work in HTML?
Brilliant! Thank you, Cynthia and everybody!
Now I can get exactly the behaviour I was looking for, using ODS HTML3 FILE=filespec ...; and after that using ODS HTML3 STYLE=style; to change style where desired.
Maybe there's a good book I should buy that really sets out the conceptual underpinnings of all this.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.