BookmarkSubscribeRSS Feed
albertsamaniego
Fluorite | Level 6

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

1 REPLY 1
Cynthia_sas
Diamond | Level 26

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 1238 views
  • 2 likes
  • 2 in conversation