This can be done by applying a behavior which is an HTC file (HTML component file). This HTC file includes JavaScript and XML tags. There are default behaviors built into the browser which do not require a separate HTC file, but this example uses an external file, sort.htc.
To add the behavior to the table tag, use the behavior CSS style property within the HTMLSTYLE= attribute. The file can be modified to add other events, and you can combine multiple behaviors
within the table. The original sort.htc file was modified to reduce the size of the blank image. The sort1.htc file was modified to include up and down arrows when the header is clicked. In addition, the first column, which is the OBS column, is prevented from being sorted.
This example will produce an error in SAS 9.1 without some modifications. The JavaScript expects every table header to be enclosed within <TD> tags; however, SAS 9.1 places the headers in <TH> tags. You can either modify the tagset to make the
script happy, or use HTML 3.2 by specifying the ODS HTML3 desination. See
sort.htc output and
sort1.htc output. See
sort.htc source or
sort1.htc source.
Use the following example code for SAS 8.2:
ods html file="c:\temp.html" ;
proc print
data=sashelp.class
style(table)={htmlstyle='behavior:url(c:\sort.htc)'};
run;
ods html close;
Use the following example code for SAS 9.1:
ods html3 file="c:\temp.html" ;
proc print
data=sashelp.class
style(table)={htmlstyle='behavior:url(c:\sort.htc)'};
run;
ods html3 close;
The next example uses a different HTC file which is diffsort.htc. This sorts all of the data as a string by default. With this behavior, we have the ability to determine how each column is sorted individually. The parameters that we can pass the behavior determine how the columns are sorted. The parameters are String(default), CaseInsensitiveString( compares string values but differentiates between "a" and "A"), Date, and Number. The file also has an up and down arrow which is define in the .HTC file. As the above example, to run this in SAS 9.1, use the ODS HTML3 destination. Below is an example of applying this. View output and the .HTC file
ods html file="temp.html" headtext="<style> .arrow {font-family:webdings}</style>";
proc report data=sashelp.class nowd
style(report)={htmlstyle="behavior:url(c:\tablesort.htc)"};
define age / style(header)={tagattr='type="Number"'};
define height / style(header)={tagattr='type="Number"'};
define weight / style(header)={tagattr='type="Number"'};
define sex / style(header)={tagattr='type="CaseInsensitiveString"'};
run;
ods html close;
See also the full PROC TEMPLATE FAQ and Concepts.
Operating System and Release Information
SAS System | Base SAS | Windows | n/a | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.