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.
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.
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 |
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?
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 |
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;
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.
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.
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/
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.