The SAS Output Delivery System and reporting techniques

how template is linked with a style?

Reply
N/A
Posts: 0

how template is linked with a style?

hello,

can anyone explain how sas links a table definition with a style?

for example, I have this:

ods listing close;

ods html style=default;

ods trace on;

data _null_;
set sashelp.cars (keep=make model);
where make='Acura';
file print ods;
put _ods_;
run;

Looking at the table component " Base.Datastep.Table" and at the style "Default",
I could find no evidence of how sas binds these together, so it produces the formatted output object.

the output objects may have some characteristics already defined (where ?), characteristics that we can find in the style definition?

for example the "class TitlesAndFooters" from the default style has a corresponding element "TitlesAndFooters" in the background definition of output object?

Thank you,
Marius
SAS Super FREQ
Posts: 8,866

Re: how template is linked with a style?

Posted in reply to deleted_user
Hi:
For ODS HTML, you can open the HTML file that's been created with Notepad or any text editor. Scroll past the inline <STYLE> section and look for your data rows. You will find CLASS= style attributes in the HTML. Attributes like: CLASS="Header" or CLASS="SystemTitle" or CLASS="Data". Each class selector in the HTML will link directly back to a style element in the style template. For example, the <TABLE> section from your output looks like this:
[pre]
<table class="Table" cellspacing="1" cellpadding="7" rules="groups" frame="box" border="1"
bordercolor="#000000" summary="Procedure Datastep: FilePrint1">
<colgroup>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="c b Header" scope="col">Make</th>
<th class="c b Header" scope="col">Model</th>
</tr>
</thead>
<tbody>
<tr>
<td class="l Data">Acura</td>
<td class="l Data">MDX</td>
</tr>
<tr>
<td class="l Data">Acura</td>
<td class="l Data">RSX Type S 2dr</td>
</tr>
<tr>
<td class="l Data">Acura</td>
<td class="l Data">TSX 4dr</td>
</tr>
<tr>
<td class="l Data">Acura</td>
<td class="l Data">TL 4dr</td>
</tr>
<tr>
<td class="l Data">Acura</td>
<td class="l Data">3.5 RL 4dr</td>
</tr>
<tr>
<td class="l Data">Acura</td>
<td class="l Data">3.5 RL w/Navigation 4dr</td>
</tr>
<tr>
<td class="l Data">Acura</td>
<td class="l Data">NSX coupe 2dr manual S</td>
</tr>
</tbody>
</table>
[/pre]

In fact, you can look at the inline <STYLE> section in the HTML -- but the information that's in the HTML in-line style section was translated from the ODS style template.

All SAS tabular output when sent to a destination that supports style (not LISTING) -- has the style template information "translated" from style template form into a form that's appropriate to the destination. So that's how ODS HTML gets an inline style section. ODS MSOFFICE2K gets style info in a Microsoft-friendly format. ODS LaTeX inserts style info in a LaTeX appropriate way. ODS RTF inserts style info following RTF rules. It doesn't really matter if your tabular output is created with the DATA step, PROC SQL, PROC GLM, PROC MEANS or PROC PRINT, etc.

A table is a table is a table is a table. SAS tabular output may or may not have SystemTitles in effect. SAS tabular output probably has Header cells being created in the output. SAS tabular output probably has Data cells being created in the output. SAS tabular output may or may not have NoteContent being used. SAS tabular output may or may not have RowHeader cells being created.

ODS TRACE ON will only tell you the names of the output objects being created by the program or procedure and will only tell you the name of the TABLE template associated with that output object. If you look at the TABLE template for Base.Datastep.Table, you don't see any explicit style information, because the output object built by the Data step is a simple output object and the table created really only has Header cells and Data cells.

If you look at the overview of template processing in this paper (on page 5)
http://support.sas.com/resources/papers/proceedings09/227-2009.pdf
...you will see that, conceptually, the style template information doesn't get applied until AFTER the table template has been used to make the output object. If the table template used to build the output object -does- have style override information, that style information (from the table template) will override what would normally come from the style template.If the output object is being sent to an output dataset (using ODS OUTPUT), then any style information from the TABLE template would be ignored. But if the object is going forward to a destination that supports style, then the style information in the TABLE template will override style information from the style template.

For example, see the code below where the use of the Header style is explicitly specified in a custom template -- but for numeric variables, the style template header color will be overridden with a PINK color and for character variables, the header color will be overridden with a GREEN color.
[pre]
ods path work.datatemp(update)
sasuser.templat(update)
sashelp.tmplmst(read);

proc template;
define table Base.Datastep.MySpecial;
notes "Changed DATA Step Table Definition";
column _numvar_ _charvar_;

define _numvar_;
define header n_hdr;
text _label_;
just = c;
style=Header{background=pink};
end;
header = n_hdr;
generic;
end;

define _charvar_;
define header c_hdr;
text _label_;
just = c;
style=Header{background=cx00cc33};
end;
header = c_hdr;
generic;
end;
justify;
order_data;
end;
run;

ods html(1) file='c:\temp\changestyle1.html'
style=default;
ods html(2) file='c:\temp\changestyle2.html'
style=sasweb;
ods rtf file='c:\temp\changestyle.rtf';

data _null_;
set sashelp.class(obs=4);
file print ods=(template='Base.Datastep.MySpecial'
columns=(_charvar_=name(generic=on)
_numvar_=age(generic=on)
_charvar_=sex(generic=on)
_numvar_=height(generic=on)));
put _ods_;
run;

data _null_;
set sashelp.cars(obs=4);
file print ods=(template='Base.Datastep.MySpecial'
columns=(_charvar_=Make(generic=on)
_charvar_=Model(generic=on)
_numvar_=cylinders(generic=on)
_numvar_=mpg_city(generic=on)));
put _ods_;
run;
ods _all_ close;
[/pre]

If you review the output for each of the files created above, you will see that the style override from the TABLE template only impacts the background color of the header cells. The rest of the output's style comes directly from the style template.

When an output object is created and sent forward to a destination, ODS "knows" that a column header should use the Header style element and that a data cell should use the Data style element and that for some procedures, row header information, such as that created by PROC FREQ or PROC TABULATE should use the RowHeader style element. Procedure title information (The FREQ Procedure, The MEANS Procedure) should use the ProcTitle element and the SAS title text strings should be styled with the SystemTitle style element. You can override these basic associations but for most output, most folks find a STYLE template that suits them and then they override the things they want to change.

For procedures like PROC PRINT, PROC REPORT and PROC TABULATE, each procedure has a way, directly in the procedure syntax to override the style information that will come from the style template. (But that's a different post topic.)

cynthia
N/A
Posts: 0

Re: how template is linked with a style?

Posted in reply to deleted_user
Thank you, Cynthia!

Now is much more clear Smiley Happy
Regular Contributor
Posts: 241

Re: how template is linked with a style?

Posted in reply to deleted_user
Cynthia's paper, Tiptoe through the Templates, is the *best* overview, so far, of the ever-present ODS and a *must* read for anyone who uses SAS seriously. "Figure 3: Table Templates and the ODS Process" on page 5 alone is worth hundreds of pages of ODS manuals. Highly recommended.
Ask a Question
Discussion stats
  • 3 replies
  • 199 views
  • 0 likes
  • 3 in conversation