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
SAS Super FREQ

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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