The SAS Output Delivery System and reporting techniques

ODS HTML, proc tabulate, proc template, how to change style?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

ODS HTML, proc tabulate, proc template, how to change style?

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

http://support.sas.com/documentation/cdl/en/odsug/65308/HTML/default/viewer.htm#n19a4b40swc766n18qcz...

*/


Accepted Solutions
Solution
‎09-26-2014 10:50 PM
SAS Super FREQ
Posts: 8,743

Re: ODS HTML, proc tabulate, proc template, how to change style?

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


how_use_style_definitions_diff_tables.png

View solution in original post


All Replies
Super User
Posts: 10,500

Re: ODS HTML, proc tabulate, proc template, how to change style?

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;

Occasional Contributor
Posts: 10

Re: ODS HTML, proc tabulate, proc template, how to change style?

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?

http://support.sas.com/kb/23/660.html

Super User
Posts: 10,500

Re: ODS HTML, proc tabulate, proc template, how to change style?

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.

Super User
Posts: 17,829

Re: ODS HTML, proc tabulate, proc template, how to change style?

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.

Solution
‎09-26-2014 10:50 PM
SAS Super FREQ
Posts: 8,743

Re: ODS HTML, proc tabulate, proc template, how to change style?

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


how_use_style_definitions_diff_tables.png
Super User
Posts: 17,829

Re: ODS HTML, proc tabulate, proc template, how to change style?

Does that work in HTML3 only, it didn't work in HTML?

Occasional Contributor
Posts: 10

Re: ODS HTML, proc tabulate, proc template, how to change style?

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.

☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 714 views
  • 6 likes
  • 4 in conversation