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

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...

*/

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

7 REPLIES 7
ballardw
Super User

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;

ajs_rdg
Fluorite | Level 6

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

ballardw
Super User

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.

Reeza
Super User

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.

Cynthia_sas
SAS Super FREQ

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
Reeza
Super User

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

ajs_rdg
Fluorite | Level 6

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1855 views
  • 6 likes
  • 4 in conversation