STYLE ON THE CLASS AND CLASSLEV STATEMENTS:
18. January 2008 10:06Sometimes we want to color the same id (or something else) in the same color.
Although not strictly a reporting procedure, one of the most important procedures in the would-be traffic lighter’s toolkit is PROC FORMAT. User defined formats allow the SAS® programmer to define foreground (font) and background color.
PROC TABULATE
In PROC TABULATE, background and foreground colors via a user-defined format can be applied in the various style statements (for example, the PROC statement, the VAR statement(s), CLASS statement(s), the CLASSLEV statements(s), the TABLES statement(s), and the BOX statement.) They can also be applied in a user-defined style template. Colors can be assigned directly in the style statement, or with a user-defined format.
STYLE ON THE PROC STATEMENT:
In general, you would not use style on the PROC TABULATE statement for the purposes of traffic lighting, as it applies an overall style to the table rather than highlights particular values. Nonetheless, it’s fun to play with while formatting your reports.
Syntax:
Proc tabulate data=yourdataset style={background=lightblue}; This would create a light blue background for your table regardless of what overall style you use.
proc sort nodupkey data=all_r out=list_value; by id; run ;
proc sql;
create table formats as
select a.id as start,
a.id as end ,
color as label,
'color' as fmtname
from
(select a.* ,monotonic() as misp
from list_value a ) a,
color1 b
where a.misp=(b.misp-5);
quit;I calculate misp-5 in order to remove the black color.
File with colors: color.csv (557.00bytes)
data all_r1;
set all_r;
code=id;
run;
proc format cntlin=formats ;
run;
proc sql;
create table all_r1 as
select a.* ,monotonic() as misp
from all_r1 a;
quit;
ods html file = 'c:\print_results.html';
Proc tabulate data=all_r1 ;
class misp code;
Var id new_new_id exposure;
table misp*code ,
id=' '*( min= 'id' *f=comma10. )*[style=[background=color. font_weight=bold]]
exposure=' '*( mean= 'exposure' *f=comma10. )*[style=[ font_weight=bold]];
run;
The result:
| The SAS System |
| id | exposure | ||
| misp | code | 15 | 131 |
| 1 | 15 | ||
| 2 | 15 | 15 | 141 |
| 3 | 15 | 15 | 151 |
| 4 | 15 | 15 | 161 |
| 5 | 16 | 16 | 141 |
| 6 | 17 | 17 | 131 |
| 7 | 17 | 17 | 178 |
| 8 | 18 | 18 | 146 |
| 9 | 18 | 18 | 148 |
| 10 | 19 | 19 | 131 |

Email 
1/20/2008 11:33:20 AM
Nice trick!
U can show two variables on this result by using color(<i>background=color.</i>) and size (<i><b>font_size=6</b></i>).
And if in a case of ODS HTML, U can achive a better results bu using CSS (Nice trick!
U can show two variables on this result by using color(<i>background=color.</i>) and size (<i><b>font_size=6</b></i>).
And if in a case of ODS HTML, U can achive a better results bu using CSS (http://www.w3.org/Style/CSS/).
And, give me a brake, IMHO, TABULATE is the past of SAS code, at least PROC REPORT!!!).
And, give me a brake, IMHO, TABULATE is the past of SAS code, at least PROC REPORT!!!
Vadim Danilov