STYLE ON THE CLASS AND CLASSLEV STATEMENTS:

by Irina 18. January 2008 10:06

Sometimes 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.

We can use the original table(list) in order to make the format
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

 idexposure
mispcode15131
115
21515141
31515151
41515161
51616141
61717131
71717178
81818146
91818148
101919131

Related posts

Comments

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

1/21/2008 11:24:01 PM

Hi Vadim, Thank you for response (comment). I’ll try to upgrade the version.
Irena

Irina

Add comment


(will show your Gravatar icon)  





Live preview

2/5/2012 9:21:25 PM

 

About the author

Irina Spivak Irina Spivak
Team Leader at G-Stat. More...


Send mail Email

Blogroll

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2012

    Sign in

    eXTReMe Tracker