The sample program below produces the attached HTML file (Win 7 32 bit, SAS 9.3 TS1M2). This is a simplified version of a much a bigger report that I'm currently doing by pre-processing the data and outputing with Proc Report. I want to switch to Proc Tabulate because that would allow me to eliminate the pre-processing step. The problem is I can't get Tabulate to format the output to meet the project specs. Specifically, the column headers' background color needs to vary by class level. I've got it for the class levels themselves using a format, but I want the statistic keaders under the class headers to "inherit" the color of their corresponding class level and I can't seem to get that figured out.
To clarify, if you look at the example (tabtest.html), the backgrounds for "N" and "%" under the "Individual" header should be yellow, and the "N" and "%" under the "Group" header should be light green. Any advice on how I can get that?
Thanks in advance!
Karl
Sample program:
data one;
input InVsGr X Ctr;
datalines;
1 1 5
1 2 20
1 3 35
2 1 50
2 2 65
2 3 80
;;;;
run;
proc format;
value f1f
1 = "Individual"
2 = "Group";
value f2f
1 = "Cat 1"
2 = "Cat 2"
3 = "Cat 3";
value c1f
1 = "yellow"
2 = "light green";
quit;
ods html file="c:\windows\temp\tabtest.html";
proc tabulate data = one;
class InVsGr X;
table X=' ',
InVsGr=' ' * (n='N' pctn<X>='%') /
box = [label = 'Label Placeholder'];
classlev InVsGr / style = [background=c1f.];
freq ctr;
format InVsGr f1f. X f2f.;
title 'Proc Tabulate Test';
run;
Hi,
I don't have time to test this right now, but you might want to try using style=<parent> on the KEYWORD statement for the N and PCTN statistic, something like this:
keyword n pctn / style=<parent>;
(that is < parent > as: less than symbol parent greater than symbol with no spaces between -- not sure how the forum will represent the < and > signs)
cynthia
Never mind, my friends. Figured it out. I found an old paper by Cynthia@sas in which she reminded me of the <parent> style syntax.
If you're interested, I just needed to add the following:
keyword n pctn / style = <parent>;
Hi,
I don't have time to test this right now, but you might want to try using style=<parent> on the KEYWORD statement for the N and PCTN statistic, something like this:
keyword n pctn / style=<parent>;
(that is < parent > as: less than symbol parent greater than symbol with no spaces between -- not sure how the forum will represent the < and > signs)
cynthia
Thanks, Cynthia. I knew you'd know, so I purposely tagged you in my "Oops, I figured it out" reply, in the hopes you'd see that and not waste your time with a response to my OP.
Anyway, thanks as always for your wisdom. Now if I could just figure out a general way to do green bar shading without pre-processing the data, I might actually come to like Proc Tabulate.
Karl
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.