ODS alternating row color

Reply
Regular Contributor
Posts: 229

ODS alternating row color

Hi,

I would like to be able to create a table that alternates the row color to distinguish between cities. However, the variable cities is not unique as it is possible for the city to appear in the table more than once. I would like to keep and have each different city the same color and alternating colors between different cities......any suggestions would be greatly appreciated...thanks.

Super User
Posts: 11,343

Re: ODS alternating row color

What procedure are you using to generate your output?

In some procedures you can provide style overrides for background color using a format based on the value displayed.

Regular Contributor
Posts: 229

Re: ODS alternating row color

Hi Ballardw,

I am using the proc report procedure....and would like it to alternating between white and grey for each different city so as to identify the results for each city .

CityDepartmentEmployees
VancouverEngineering23
EdmontonAdministration14
EdmontonPublic Transportation34
CalgaryEngineering27
SaskatoonAdministration20
SaskatoonPublic Transportation13
SaskatoonEngineering21
ReginaAdministration9
ReginaPublic Transportation13
WinnipegEngineering18
Super User
Posts: 19,815

Re: ODS alternating row color

How many cities do you have? Do you want to control the color of the cities or have them automatically selected, which could be interesting if you have a lot of cities.

I'm a bit confused with the alternating colour yet each city the same color? Do you want 2 colors that alternate, but this is done for multiple rows at a time or should each city have its own color?

Regular Contributor
Posts: 229

Re: ODS alternating row color

Hi Reeza,

The number of cities can vary from time to time depending when the program is ran and the time of year that the data is being extracted. I am not too concern about the colors (white and grey is fine) as long as it is possible to distinguish the result on the table between cities.

CityDepartmentEmployees
VancouverEngineering23
EdmontonAdministration14
EdmontonPublic Transportation34
CalgaryEngineering27
SaskatoonAdministration20
SaskatoonPublic Transportation13
SaskatoonEngineering21
ReginaAdministration9
ReginaPublic Transportation13
WinnipegEngineering18
Occasional Learner
Posts: 1

Re: ODS alternating row color

hi,

this can be done in proc report, by using a line number and checking if it is even or odd.

something along the lines of

proc report.....

      compute LINE_COLOR;

        if mod(LINE_COLOR, 2) gt 0 then

          call define(_ROW_,'STYLE','style=[background=LIGHTGRAY]');

      endcomp;

run;

Super Contributor
Posts: 253

Re: ODS alternating row color

Posted in reply to test999999

This is the basic concept, but then you'd want to change this from instead of incrementing every single row, increment only when you have a change in city.  Perhaps just store the last-seen city name and alter the color when it's not the same as the current one.

Occasional Contributor
Posts: 12

Re: ODS alternating row color

data colors;
set sashelp.shoes;
where Subsidiary in('Addis Ababa' 'Algiers' 'Cairo' 'Khartoum');
run;

ods html;
proc report data=colors nowd;
column subsidiary sales;
define subsidiary / display;
define sales / display;

compute subsidiary;
if subsidiary='Addis Ababa' then
    call define(_row_,
"style","style={background=green}");
else if subsidiary='Algiers' then
    call define(_row_,
"style","style={background=blue}");
else if subsidiary='Cairo' then
    call define(_row_,
"style","style={background=red}");
else if subsidiary='Khartoum' then
    call define(_row_,
"style","style={background=orange}");
endcomp;
where sales gt 70000;
run;
ods html close;
Super Contributor
Posts: 253

Re: ODS alternating row color

Posted in reply to Scott_C_Moore

Modified to simply alternate:

data colors;

set sashelp.shoes;

where Subsidiary in('Addis Ababa' 'Algiers' 'Cairo' 'Khartoum');

run;

ods html;

proc report data=colors nowd;

column  subsidiary sales;

define subsidiary / order;

define sales / display;

compute before subsidiary;

  colorcol+1;

endcomp;

compute subsidiary;

  if mod(colorcol,2)=1 then

  call define(_row_,"style","style={background=green}");

  else

  call define(_row_,"style","style={background=blue}");

endcomp;

where sales gt 70000;

run;

ods html close;

You can also do something like this in PROC TABULATE; see http://support.sas.com/resources/papers/stylesinprocs.pdf for examples of using CLASSLEV and formats to modify row colors.

Regular Contributor
Posts: 229

Re: ODS alternating row color

Posted in reply to Scott_C_Moore

Hi Scott...thanks for your suggestion. The problem is that I do not know in advance how many cities will be in the table and for the most part, it would seem like it could be numerous cities....so specifying a color for a particular city would not work for me but I am fine with it alternating between white and grey....Thanks once again/

Ask a Question
Discussion stats
  • 9 replies
  • 1243 views
  • 0 likes
  • 6 in conversation