BookmarkSubscribeRSS Feed
Daily1
Quartz | Level 8
I’m using PROC TABULATE in SAS to create a table with nested row headers (e.g., sec_sr_no='Sr. No.', SECTOR_NAME='Sector', subsec_sr_no='Sr. No.', SUB_SECTOR_NAME='Sub-Sector') and a summarized variable (Ext_tot_Outlay with SUM). My current code is:
 

PROC TABULATE DATA=dataset FORMAT=COMMA12.; CLASS sec_sr_no SECTOR_NAME subsec_sr_no SUB_SECTOR_NAME; VAR Ext_tot_Outlay; TABLE sec_sr_no='Sr. No.' * SECTOR_NAME='Sector' * subsec_sr_no='Sr. No.' * SUB_SECTOR_NAME='Sub-Sector', Ext_tot_Outlay='Annual' * SUM='Exp'; RUN;
I’d like the headers (Sr. No., Sector, Sr. No., Sub-Sector) to "shift up" in the output

 

Daily1_0-1743761122141.png

i want 

Daily1_1-1743761215885.png

Is there an option in PROC TABULATE to adjust the vertical placement or spacing of row headers? If not, what’s the best alternative (e.g., PROC REPORT) to achieve this customization?

Thank you!

4 REPLIES 4
Ksharp
Super User

Nope. But you can use PROC REPORT to achieve this report.

 

PROC REPORT DATA=sashelp.heart nowd;
column status sex bp_status smoking_status ('Annual' weight);
define status/group 'Sr. No.' ;
define sex/group 'Sector';
define bp_status/group 'Sr. No.';
define smoking_status/group 'Sub-Sector';
define weight/analysis sum 'Exp' f=COMMA12.;
run;

Ksharp_0-1743765250864.png

 

Daily1
Quartz | Level 8

Thanks For your Respose, But i want the headers (Sr. No., Sector, Sr. No., Sub-Sector) to be moved up in the output

Daily1_0-1743768181619.png

 

Ksharp
Super User

That would be a little complicated.

 



proc summary data=sashelp.heart nway;
class status sex bp_status smoking_status;
var weight;
output out=have sum=;
run;
data have2;
 set have(drop=_:);
 by  status sex bp_status smoking_status;
 if not first.status then call missing(status);
 if not first.sex then call missing(sex);
 if not first.bp_status then call missing(bp_status);
 if not first.smoking_status then call missing(smoking_status);
run;



ods rtf file="c:\temp\odsr_column_span.rtf" style=minimal;
title "Complex Column Spanning";
data _null_; 
  set have2 end=last; 
  if _N_ = 1 then do; 
      dcl odsout obj(); 
      obj.table_start(); 
      obj.head_start(); 
	  ** Header row 1;
	  obj.row_start(type:"Header");
	  obj.format_cell(text: "status", row_span:2,style_attr:"color=black  vjust=m "); 
      obj.format_cell(text: "sex", row_span:2, style_attr:"color=black  vjust=m"); 
      obj.format_cell(text: "bp_status", row_span:2, style_attr:"color=black vjust=m"); 
      obj.format_cell(text: "smoking_status", row_span:2, style_attr:"color=black  vjust=m"); 
      obj.format_cell(text: "Annual", row_span:1, style_attr:"color=black "); 
      obj.row_end(); 
	  ** Header row 2;
	  obj.row_start(type:"Header");
      obj.format_cell(text: "Exp",  row_span:1, style_attr:"color=black"); 
      obj.row_end();  
	  obj.head_end(); 
    end;
  ** row for every obs;
      obj.row_start(); 
      obj.format_cell(data: status, row_span:1); 
      obj.format_cell(data: sex, row_span:1); 
      obj.format_cell(data: bp_status, row_span:1);
      obj.format_cell(data: smoking_status, row_span:1); 
      obj.format_cell(data: weight, row_span:1); 
	  obj.row_end();
  if last then do; 
      obj.table_end(); 
  end; 
run; 
ods rtf close;
title; footnote;

Ksharp_0-1743770434083.png

 

Cynthia_sas
Diamond | Level 26

Hi:

  Why do you need a cell division between the word "Annual" and "Exp"?

  Using the SASHELP.HEART data you could do this with PROC REPORT if you put Annual and Exp in the same header cell:

Cynthia_sas_0-1743779943967.png

Cynthia

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4 replies
  • 814 views
  • 3 likes
  • 3 in conversation