Desktop productivity for business analysts and programmers

Help to customize css styles for EG

Not applicable
Posts: 0

Help to customize css styles for EG

How can I customize or create a style that will alternately change colors for data rows?

For Example:

col1 col2
row 1 one two <----- Should be color white
row 2 two one <----- Should be a different color
Posts: 9,425

Re: Help to customize css styles for EG

Posted in reply to deleted_user
It sort of depends on what procedure you want to do this with. Do you want to see alternating colors no matter WHAT procedure you use (alternating colors for PROC FREQ, PROC MEANS) or do you want to see alternating colors for a "List Data" task?

The challenge comes in because every DATA cell in a SAS output/report table is formatted with the CSS style for "DATA" (or the style template element "DATA") .... you CAN change your CSS file to have DATA1 and DATA2 style properties. But then the task becomes how to tell SAS to use DATA1 for the odd rows and DATA2 for the even rows. Just because the style properties are in the CSS file, doesn't mean that SAS will automatically use the style properties.

It is fairly easy to change row colors if you use PROC REPORT (instead of the LIST DATA task) to change the style of a _ROW_. For other procedures, you'd have to get into a change to the table template used for each color (because the other procedures are controlled by table templates). But for PROC REPORT you can make the change in a COMPUTE block:
ods listing close;
** direct method;
** Create alternating colors by using a temporary;
** variable and a CALL DEFINE.;
ods html file='rep_altbar.html' style=sasweb;
proc report data=sashelp.class nowd
title 'Highlight Every Other Row';
column name age height;
define name / order;
define age / display;
define height / display;
compute name;
tempvar + 1;
if mod(tempvar,2) = 0 then
call define(_ROW_,'STYLE','style={background=#ccccff}');
ods html close;
ods listing;

So the above method doesn't even use just makes the change directly using the CALL DEFINE statement to change the background color of the alternating rows.

If you DID have a CSS file with DATA1 and DATA2, then you could do this with PROC REPORT:
[pre]ods html path='c:\temp'

proc report data=sashelp.class nowd;
column name age height;
define name / order;
define age /display;
define height/display;

compute name;
tmpvar + 1;
if mod(tmpvar,2) = 0 then call define(_ROW_,'STYLE',
else if mod(tmpvar,2) ne 0 then call define(_ROW_,'STYLE',
ods html close;

Or, if you really wanted other procedures and not the equivalent of the LIST data task, in SAS 9.2, you could make a change to the "base" table template that every other table template (FREQ, MEANS, etc) would inherit from.

Until SAS 9.2, one other possible way to get alternating row colors is to use the TAGSETS.TABLEEDITOR destination, as described in this paper:

(However, to make this destination work in EG, you'd have to download the template and then make sure that it was installed on the server machine, in a location that was going to be available every time you ran your jobs. You'd probably also need an ODS PATH statement added to your AUTOEXEC.SAS or EGAUTO.SAS files to make sure that the new template was always accessible.)

At any rate, you have possibilities. If you need help figuring this out in more detail, you might consider contacting Tech Support.

Not applicable
Posts: 0

Re: Help to customize css styles for EG

Posted in reply to Cynthia_sas
Thank you very much for your help Cynthia!!!
Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation