BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi Folks,

I know how to do it for PROC Report, but I'm not quite sure how to translate it to Tabulate. To enhance readability, I'd like to alternate the shading of the rows of my report based on my main class variable. Picture a "greenbar" report, I guess, only using gray and white instead of green and white.

Any suggestions? Thanks!
1 REPLY 1
David_SAS
SAS Employee
The expressive power of REPORT becomes apparent when you try to do alternating row colors in TABULATE. It's possible for
some tables, but complicated. The solution is to use traffic lighting of row headers combined with the style parenting syntax . Here's an example:
[pre]
options nocenter;

ods html body="band.html"; ods listing close;

title;

data;
input region $ citysize $ pop product $ saletype $
quantity amount;
cards;
NC S 25000 A100 R 150 3750.00
NE S 37000 A100 R 200 5000.00
SO S 48000 A100 R 410 10250.00
WE S 32000 A100 R 180 4500.00
NC M 125000 A100 R 350 8750.00
NE M 237000 A100 R 600 15000.00
SO M 348000 A100 R 710 17750.00
WE M 432000 A100 R 780 19500.00
NE L 837000 A100 R 800 20000.00
SO L 748000 A100 R 760 19000.00
WE L 932000 A100 R 880 22000.00
NC S 25000 A100 W 150 3000.00
NE S 37000 A100 W 200 4000.00
WE S 32000 A100 W 180 3600.00
NC M 125000 A100 W 350 7000.00
NE M 237000 A100 W 600 12000.00
SO M 348000 A100 W 710 14200.00
WE M 432000 A100 W 780 15600.00
NC L 625000 A100 W 750 15000.00
NE L 837000 A100 W 800 16000.00
SO L 748000 A100 W 760 15200.00
WE L 932000 A100 W 880 17600.00
NC S 25000 A200 R 165 4125.00
NE S 37000 A200 R 215 5375.00
SO S 48000 A200 R 425 10425.00
WE S 32000 A200 R 195 4875.00
NC M 125000 A200 R 365 9125.00
NE M 237000 A200 R 615 15375.00
SO M 348000 A200 R 725 19125.00
WE M 432000 A200 R 795 19875.00
NE L 837000 A200 R 815 20375.00
SO L 748000 A200 R 775 19375.00
WE L 932000 A200 R 895 22375.00
NC S 25000 A200 W 165 3300.00
NE S 37000 A200 W 215 4300.00
WE S 32000 A200 W 195 3900.00
NC M 125000 A200 W 365 7300.00
NE M 237000 A200 W 615 12300.00
SO M 348000 A200 W 725 14500.00
WE M 432000 A200 W 795 15900.00
NC L 625000 A200 W 765 15300.00
NE L 837000 A200 W 815 16300.00
SO L 748000 A200 W 775 15500.00
WE L 932000 A200 W 895 17900.00
NC S 25000 A300 R 157 3925.00
NE S 37000 A300 R 208 5200.00
SO S 48000 A300 R 419 10475.00
WE S 32000 A300 R 186 4650.00
NC M 125000 A300 R 351 8725.00
NE M 237000 A300 R 610 15250.00
SO M 348000 A300 R 714 17850.00
WE M 432000 A300 R 785 19625.00
NE L 837000 A300 R 806 20150.00
SO L 748000 A300 R 768 19200.00
WE L 932000 A300 R 880 22000.00
NC S 25000 A300 W 157 3140.00
NE S 37000 A300 W 208 4160.00
WE S 32000 A300 W 186 3720.00
NC M 125000 A300 W 351 7020.00
NE M 237000 A300 W 610 12200.00
SO M 348000 A300 W 714 14280.00
WE M 432000 A300 W 785 15700.00
NC L 625000 A300 W 757 15140.00
NE L 837000 A300 W 806 16120.00
SO L 748000 A300 W 768 15360.00
WE L 932000 A300 W 880 17600.00

proc format;
value $salefmt 'R'='Retail'
'W'='Wholesale';

/*-- define region background color --*/

value $regcol 'NC'='CX37E139'
'NE'='CXDFFDC5'
'SO'='CX37E139'
'WE'='CXDFFDC5';


proc tabulate;
class region citysize saletype;
classlev saletype / s={background=CXDFFDC5};

/*-- assign user format to region class level value headings --*/

classlev region / s={background=$regcol.};

/*-- citysize class level value headings obey their parents --*/

classlev citysize / s=;
var quantity amount / s={background=CXDFFDC5};
keyword sum all / s={background=CXDFFDC5};
format saletype $salefmt.;
label quantity="Quantity" amount="Amount";
keylabel all="Total";


table region*citysize*

/*---------------------------------------------------------sasdck-*/
/*-- Data cell styles are parented to citysize class level --*/
/*-- value heading styles, except that the foreground is --*/
/*-- overridden. --*/
/*-- --*/
/*-- Remember that citysize class level value styles are --*/
/*-- parented to region class level value heading styles. --*/
/*-- So we're using transitive parenting to achieve the --*/
/*-- desired effect. --*/
/*--------------------------------------------------------01May98-*/

{s={foreground=black}},

(saletype=' ' all)*(quantity amount) /

indent=0
box={s={background=CXDFFDC5}}
s={background=black}
misstext="Missing";
run;

ods html close; ods listing;
[/pre]

Voila, greenbar output!

-- David Kelley, SAS

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 631 views
  • 0 likes
  • 2 in conversation