BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

Using PROC TABULATE, in a table that has two levels of columns headings, is there a way to get vertical borders between the major headings, that extend through the entire table?

 

Below I can specify a border on the CLASSLEV statement, but it only applies to the heading, it is not actually inherited by the table.

 

ods pdf file="%sysfunc(pathname(work))/foo.pdf" style=journal;
proc tabulate data=sashelp.class ;
  class name age sex;
  classlev sex/style={borderrightcolor=red borderrightwidth=2} ;
  tables name="",sex=""*age="";
  where age IN (13,14) ;
run ;
ods pdf close ;

It generates:

Quentin_0-1761927789272.png

I would like the red lines to extend down through the entire table, to separate the gender groups.

 

Perhaps this can be done with inheritance?

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Thanks @Kathryn_SAS , helpful examples.


Luckily for me,  my actual example is different than I posted.  Within the gender columns, I calculate a mean and std dev.  This allows me to specify a border on the std dev column, e.g.:

 

ods pdf file="%sysfunc(pathname(work))/foo.pdf" style=journal;
proc tabulate data=sashelp.class ;
  class name sex;
  var height ;
  classlev sex/style={borderrightcolor=red borderrightwidth=2} ;
  tables name="",sex=""*height=""*(mean stddev*{style={borderrightcolor=red borderrightwidth=2}});
  keyword stddev/style={borderrightcolor=red borderrightwidth=2} ; 
  where age IN (13,14) ;
run ;
ods pdf close ;

Quentin_0-1761939506041.png

 

View solution in original post

2 REPLIES 2
Kathryn_SAS
SAS Employee

With style inheritance, you will get more borders than you want. I tried PROC REPORT, and the trick is getting only 14 to have a right border. You can see the two attempts I tried below, which still does not give you exactly what you describe. I think you can adapt this SAS Note which requires creating multiple formats:

https://support.sas.com/kb/39/652.html

ods listing close;
ods escapechar='^';
ods pdf file="c:\temp\foo.pdf" style=journal;

proc tabulate data=sashelp.class ;
  class name sex;
  class age / style=<parent>;
  classlev sex/style={borderrightcolor=red borderrightwidth=2} ;
  classlev age/ style=<parent>;
  tables name="",sex=""*age=""*[style=<parent>];
  where age IN (13,14) ;
  keyword n / style=<parent>;
run ;

proc report data=sashelp.class missing;
column name sex,((age,n)) dummy ;
define name / ' ' group;
define sex / across ' ' style(header)=[borderrightcolor=red borderrightwidth=2];
define age / across ' ' style(header)=[borderrightcolor=red borderrightwidth=2];
define n / ' ';
define dummy / computed noprint;
where age IN (13,14) ;

compute dummy;
call define('_c3_','style','style=[borderrightcolor=red borderrightwidth=2]');
call define('_c5_','style','style=[borderrightcolor=red borderrightwidth=2]');
endcomp;
run;

data class;
set sashelp.class;
blankcol=1;
run;

proc report data=class missing;
column name sex,((age,n) blankcol);
define name / ' ' group;
define sex / across ' ' style(header)=[borderrightcolor=red borderrightwidth=2];
define age / across ' ' ;
define n / ' ';
define blankcol / ' ' style(column header)=[foreground=red background=red cellwidth=.1in];
where age IN (13,14) ;

run;

ods pdf close ;
ods listing;
Quentin
Super User

Thanks @Kathryn_SAS , helpful examples.


Luckily for me,  my actual example is different than I posted.  Within the gender columns, I calculate a mean and std dev.  This allows me to specify a border on the std dev column, e.g.:

 

ods pdf file="%sysfunc(pathname(work))/foo.pdf" style=journal;
proc tabulate data=sashelp.class ;
  class name sex;
  var height ;
  classlev sex/style={borderrightcolor=red borderrightwidth=2} ;
  tables name="",sex=""*height=""*(mean stddev*{style={borderrightcolor=red borderrightwidth=2}});
  keyword stddev/style={borderrightcolor=red borderrightwidth=2} ; 
  where age IN (13,14) ;
run ;
ods pdf close ;

Quentin_0-1761939506041.png

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 560 views
  • 4 likes
  • 2 in conversation