The SAS Output Delivery System and reporting techniques

Moved spanned columns on other rows

Reply
Occasional Contributor
Posts: 6

Moved spanned columns on other rows

I have a code here that adds spanned columns on proc report.

 

proc report nowd data=sashelp.class(obs=5);
col (
     ('this is spanned'
     ('A' age sex) ('B' weight height) 
    ) 
);
run;

The output would be like this

output 1.PNG

 

How can I output it in such a way that the spanned columns would be placed on the 2nd row like this one?

 

output span.PNG

SAS Super FREQ
Posts: 9,424

Re: Moved spanned columns on other rows

Posted in reply to albertsamaniego

Hi:

  What you want really can't be done with PROC REPORT. Once you have a header that spans ALL the columns, (like the middle header for Spanning 2 that is shown below) with PROC REPORT, the only thing that can go above it is another header that spans the entire row, like the header for Spanning 1 -- this header cannot be "split" into 2 columns with PROC REPORT:

span2_report.png

 

However, it can be done for HTML and PDF in the Report Writing Interface (RWI), as shown here:

span_5_rwi.png

 

The code that produced the screen shot is here:


ods html(id=sp) file="c:\temp\diff_span.html";
   
title '1) Detail Report';
data _null_; 
  set SASHELP.class 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: "A", column_span:3, style_attr:"fontweight=bold"); 
      obj.format_cell(text: "B", column_span:2,style_attr:"fontweight=bold"); 
      obj.row_end(); 
      ** Header row 2;
      obj.row_start(type:"Header");
      obj.format_cell(text: "Spanning All 5 Columns", column_span:5,style_attr:"background=lightyellow"); 
      obj.row_end(); 
      ** Header row 3;
      obj.row_start(type: "Header"); 
      obj.format_cell(text: "Name", style_attr:"fontweight=bold"); 
      obj.format_cell(text: "Age", style_attr:"fontweight=bold"); 
      obj.format_cell(text: "Sex", style_attr:"fontweight=bold"); 
      obj.format_cell(text: "Height", style_attr:"fontweight=bold"); 
      obj.format_cell(text: "Weight", style_attr:"fontweight=bold"); 
      obj.row_end(); 
      obj.head_end(); 
    end;
  ** row for every obs;
      obj.row_start(); 
      obj.format_cell(data: name ); 
      obj.format_cell(data: age); 
      obj.format_cell(data: sex); 
      obj.format_cell(data: height); 
      obj.format_cell(data: weight); 
      obj.row_end(); 
   
  if last then do; 
      obj.table_end(); 
    end; 
run; 
ods html(id=sp) close;

  Hope this helps,

cynthia

Ask a Question
Discussion stats
  • 1 reply
  • 281 views
  • 2 likes
  • 2 in conversation