'proc report to create table as it is
I am working on PROC REPORT. i want to crate table as it is
data have;
input A B $ C E F G I K L M N;
datalines;
1 japan 190 46 15 0 0 0 0 0 1
2 us 152 39 47 86 0 0 0 0 1
3 aus 50 6 36 41 0 0 0 0 1
;
proc report data=have;
column ("A" ("" A)) ("B" ("" B)) ("C" ("" C)) ("D" (("E" E) ("F" F))) ("G" ("" G))
("H" ("I" I) ('J' K L M) ("N" N));
define A / "" display;
define B / "" display;
define C / "" display;
define E / "" display;
define F / "" display;
define G / "" display;
define I / "" display;
define K / display;
define L / display;
define M / display;
define N / "" display;
run;
i want this type of table structure
Solution 1:[1]
I was not able to get PROC REPORT to do this. An alternative approach is given in this paper, which shows how to use the SAS Report Writing Interface to achieve this result in a data step.
(It is not compatible with SAS Report output but works for HTML, PDF etc.)
For your example, the code would be:
data _null_;
set have end=done;
* first start the table and create the header;
if _n_ eq 1 then do;
declare odsout t(); * create a report writing interface object named t;
t.table_start(); * start the table;
t.head_start(); * start the header (so that these items get the default header style);
* in this case the header is 3 rows in height. the ROWSPAN and COLSPAN items
control the size of each cell in the header;
t.row_start();
t.format_cell(text: 'A', rowspan:3);
t.format_cell(text: 'B', rowspan:3);
t.format_cell(text: 'C', rowspan:3);
t.format_cell(text: 'D', rowspan:2, colspan:2);
t.format_cell(text: 'G', rowspan:3);
t.format_cell(text: 'H', colspan:5);
t.row_end();
t.row_start();
t.format_cell(text: 'I', rowspan:2);
t.format_cell(text: 'J', colspan:3);
t.format_cell(text: 'N', rowspan:2);
t.row_end();
t.row_start();
t.format_cell(text:'E');
t.format_cell(text:'F');
t.format_cell(text:'K');
t.format_cell(text:'L');
t.format_cell(text:'M');
t.row_end();
t.head_end();
end;
* the rest of the cells are all simply data values;
t.row_start();
t.format_cell(text: A);
t.format_cell(text: B);
t.format_cell(text: C);
t.format_cell(text: E);
t.format_cell(text: F);
t.format_cell(text: G);
t.format_cell(text: I);
t.format_cell(text: K);
t.format_cell(text: L);
t.format_cell(text: M);
t.format_cell(text: N);
t.row_end();
if done then t.table_end();
run;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | shaun_m |