Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CENTER A TABLE IN ODS HTML 1

Status
Not open for further replies.

nobyrnes

Programmer
Mar 20, 2007
15
IE
Hey,
Whats the most simple way to center a table using the ODS HTML commands?
N
 
N,

If you're using CHTML, you can add the following to center all tables in your output.

Code:
HEADTEXT="<STYLE>BODY {TEXT-ALIGN: CENTER;}</STYLE>";

If you want to center text in all your table cells, the following works:

Code:
HEADTEXT="<STYLE>TD {TEXT-ALIGN: CENTER;}</STYLE>";

Accordingly, if you want to center all of your tables, and center all the cells in all of your tables, the following works:

Code:
HEADTEXT="<STYLE>BODY {TEXT-ALIGN: CENTER;}
                 TD {TEXT-ALIGN: CENTER;}</STYLE>";

Again, this is using CHTML, which creates an HTML document just like HTML. The difference is that formatting is done in the page's head tags rather than in page elements. The result is a smaller file, but one that I think is easier to format from SAS since your style tags are not overwritten at the cell tag.

HTH,
Larry
 
Thanks Larry,
What if I only want to center a few tables?
N
 
N,

That one is a bit tricky, but I managed to get something started. I based my code on Technical FAQ (3284) How can I place two tables side-by-side in ODS HTML output? from SAS. The premise is that you use [tt]PROC TEMPLATE[/tt] to define your styles. Then, use multiple ODS statements to ~print~ your data. You set the file attribute on the first ODS statement only, and you do not close the ODS HTML until you've added your last table.

Here are the proc formats that I used. My base style was SASDOCPRINTER, so I used that as the parent style. Set your parent to whatever style sheet you normally use. If you don't use one, then set it to styles.default.

Setting the tagattr's align to left/center/right is self explanatory. Setting the style='clear:both' is not. Basically, this sets the float property for the tables. Before adding this, the tables floated and I ended up with one on the left and one on the right, both really were side by side. By clearing the float, I had one above and one below. The top one was on the left as I directed, and the bottom one was on the first as I directed. One thing I did not like was that there was a <hr> tag inserted between the tables. Not really sure how to tell SAS not to include that.

Code:
PROC TEMPLATE;                                        
  DEFINE STYLE STYLES.TABLELEFT;                      
    PARENT=STYLES.SASDOCPRINTER;                      
    STYLE TABLE FROM TABLE /                          
          TAGATTR='ALIGN="LEFT" STYLE="CLEAR:BOTH;"'; 
  END;                                                
RUN;

Code:
PROC TEMPLATE;                                         
  DEFINE STYLE STYLES.TABLERIGHT;                      
    PARENT=STYLES.SASDOCPRINTER;                       
    STYLE TABLE FROM TABLE /                           
          TAGATTR='ALIGN="RIGHT" STYLE="CLEAR:BOTH;"'; 
  END;                                                 
RUN;

Here's my code for pushing both of the tables out:
Code:
ODS HTML FILE=TBLS2ODS RS=NONE STYLE=TABLELEFT         
  HEADTEXT="<STYLE> TD {MSO-NUMBER-FORMAT:\@}</STYLE>";
  TITLE;                                               
  PROC PRINT DATA=EMPS_1 NOOBS;                        
  RUN;                                                 
                                                       
ODS HTML RS=NONE STYLE=TABLERIGHT;                     
  PROC PRINT DATA=EMPS_2 NOOBS;                        
  RUN;                                                 
                                                       
ODS HTML CLOSE;

By the way, I tried this using ODS CHTML. While this elimated the hard rule (<hr>), it also eliminated all the other formatting (read: my proc templates were ignored and all styles were removed).

Anyway, that should get you started on getting the alignments set for multiple tables.

HTH,
Larry




 
N,

I found this from SAS: Technical FAQ (3243) For ODS HTML output, how can I remove the horizontal rule and the ...

Looks like you can just add [tt]style Body from Body / Pagebreakhtml=_undef_;[/tt] to the proc format. Something like this ought to work:

Code:
PROC TEMPLATE;                                        
  DEFINE STYLE STYLES.TABLELEFT;                      
    PARENT=STYLES.SASDOCPRINTER;                      
    STYLE TABLE FROM TABLE /                          
          TAGATTR='ALIGN="LEFT" STYLE="CLEAR:BOTH;"'; 
    STYLE BODY FROM BODY /
          PAGEBREAKHTML=_UNDEF_;
  END;                                                
RUN;

Just add the pagebreakhtml setting to each template and the hard rule ~should~ go away.

HTH,
Larry

 
Nice one!

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top