- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 .
City | Department | Employees |
Vancouver | Engineering | 23 |
Edmonton | Administration | 14 |
Edmonton | Public Transportation | 34 |
Calgary | Engineering | 27 |
Saskatoon | Administration | 20 |
Saskatoon | Public Transportation | 13 |
Saskatoon | Engineering | 21 |
Regina | Administration | 9 |
Regina | Public Transportation | 13 |
Winnipeg | Engineering | 18 |
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
City | Department | Employees |
Vancouver | Engineering | 23 |
Edmonton | Administration | 14 |
Edmonton | Public Transportation | 34 |
Calgary | Engineering | 27 |
Saskatoon | Administration | 20 |
Saskatoon | Public Transportation | 13 |
Saskatoon | Engineering | 21 |
Regina | Administration | 9 |
Regina | Public Transportation | 13 |
Winnipeg | Engineering | 18 |
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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/