This is a deficit for those that work in clinical reporting will no doubt be familiar with. That is Proc Report in SAS does not automatically put in the top header and footer lines. You typically do this with the “put” statement within a compute block, specifying their lengths. Straight forward enough until you add, widen the columns etc.! So how would ones adjust these lines lengths dynamically? Some companies may opt for the ‘maximum’ default length=135(say) for all tables but this is not aesthetically appealing! In this post I will demonstrate a method to adjust the lengths dynamically. An alternative would be post-processing which is not discussed here.
In order to get the width of the table you will need to accumulate the width and spacing for each ‘define statement’ in the proc report. Here is a section codes outlining how to achieve this.
options nodate nonumber orientation=landscape nocenter linesize=135;
proc report data = class nowd missing headline headskip split = '#';
by pg;
columns pg sex name agec ('Spanning Label' ('--' weightc heightc));
define pg / order order=data noprint;
define sex / order noprint;
define name / display width = %width(spacing=0, val=10, start=0,
wlim=135) "Sex# Name";
define agec / display width = %width(spacing=2, val=17) center "Age";
define weightc / display width = %width(spacing=2, val=16)
center "Weight";
define heightc / display width = %width(val=16) center "Height";
compute before sex;
line @%eval(&indent + 1) sex $sexc.;
endcomp;
compute after sex;
line @%eval(&indent + 1) ' ';
endcomp;
compute before _page_;
line @%eval(&indent + 1) %eval(&curval - &indent) * 'ƒ';
endcomp;
compute after pg;
line @%eval(&indent + 1) %eval(&curval - &indent) * 'ƒ';
endcomp;
/* title is left aligned of the table */
%resettitles(shift=0, pos=L);
/* title is centre of the table
%resettitles(shift=0, pos=C);
*/
run;
Notes:
1. %width is a macro function that return a string "&val spacing=&spacing" for example "width=10 spacing=0"
2. %width in the first call will store spacing=0 in a global macro variable &indent. In this example
(&indent + 1) resolves to 1.
3. %width will accumulate the width and spacing on each call and on its last call the total (ie the width
of the table) is stored in the global &curval macro variable.
4. %resettitles is also a macro function that extracts the titles from sashelp.vtitle. Given that you have the
value for &indent and &curval you can pad the titles accordingly.
This layout is probably the most common. That is the titles, body and footnotes are all left aligned to the edge of the margin.
This is the same as example 1 except the title is centered to the table.
Examples 3 and 4 are essentially corresponds to 1 and 2 except the left indention of the tables.
This example demonstrates that when the column width changes the width of the lines will adjust automatically.
RTF does not have this issue and in my opinion much easier to deal with. And off course a much prettier format than ASCII.