Data visualization with SAS programming

[ODS PDF] How to autofit Proc Print columns ?

Posts: 36

[ODS PDF] How to autofit Proc Print columns ?

I am using a proc print in ods pdf output.

I would like the width of the columns to autofit to the size of the headers of the table instead of the size of the data. Or is it possible to set a larger width for each column of the table with the Style Option ?

Posts: 36

Re: [ODS PDF] How to autofit Proc Print columns ?

This works :

Proc Print Data=temp label;
Id Obs / style=[just=center color=black fontsize=8PT];
Var &MyVar / style=[just=center color=black fontsize=8PT] style(column)={width=200};
Where %STR(&MyCondition);
Posts: 9,026

Re: [ODS PDF] How to autofit Proc Print columns ?

Just a note. The "width=200" will end up having an impact on the HEADER cells (the COLUMN headers) -- as seen in the report below -- it doesn't matter whether I have long labels for the headers or short labels...the same width is used for all the cells. The concept of "autofit" is an Excel or spreadsheet concept. It usuallyl doesn't apply to ODS destinations like LISTING (which uses the format width) or ODS HTML, RTF and PDF. The width=200 may give the results you want in PDF, however, PDF output can also be impacted by the UNIFORM option, as well. Also, the width=200 may not work in other destinations the way it works for you in PDF. For example, in PDF, the long labels end up wrapping to the width of 200; but in HTML, the Header cells expands, as needed.

Also, as a best practice, it is a good idea with PROC PRINT and PROC REPORT to use a LOCATION in the STYLE override, such as:

(And, this posting doesn't seem to have anything to do with SAS/GRAPH or ODS GRAPHICS -- it seems more to apply to just ODS and Base SAS Reporting -- so in the future, you might want to post questions like this to the other ODS forum.)

data class;
set sashelp.class;
length longvar $400.;
longvar = 'Twas brillig and the slithy toves did gyre and gimble in the wabe. '||
'All mimsy were the borogroves and the mome raths outgrabe. '||
'Beware the Jabberwock, my son, the jaws that bite, the claws that snatch! ' ||
'Beware the Jubjub bird and shun the frumious Bandersnatch.';

ods listing close;

ods html file='c:\temp\pp.html' style=sasweb;
ods pdf file='c:\temp\pp.pdf' ;

Proc Print Data=class label;
title 'Note how style override without location applies to both header and data cells';
title2 'As seen with everything RED, CENTERED and 8 pt for NAME';
title3 'Also note how width of 200 is used -- no matter what value for HEADER is';
title4 'But you will get different results for HTML and PDF.';
Id name / style=[just=center backgroundcolor=red color=black fontsize=8PT];
Var sex age height weight longvar/
style(header)=[just=center color=black fontsize=8PT]
Where age gt 14;
label name = 'N'
height = 'H'
longvar='Jabberwocky by Lewis Carroll';
ods _all_ close;
Posts: 36

Re: [ODS PDF] How to autofit Proc Print columns ?

Okay, thank you Cynthia.
Ask a Question
Discussion stats
  • 3 replies
  • 2 in conversation