Autofit column width in proc print

Reply
Contributor
Posts: 38

Autofit column width in proc print

[ Edited ]

 This issue happens on Jupyter Notebook using sas_kernel.

 

Proc SQL inobs=20;

Select * from have;
Quit;

The code above outputs a table in which data overlaps as in shown below:

 

overlap.JPG

I would like to outfit every column to the max between the header length and the data length. I don't want to define this manually for every column.

How do I do this?

 

Thanks.

Trusted Advisor
Posts: 1,683

Re: Autofit column width in proc print

Posted in reply to Autotelic

Try to increase OPTIONS  LineSize= ...;

Super User
Posts: 12,148

Re: Autofit column width in proc print

Posted in reply to Autotelic

What destination are you printing to? What application is that screen shot from?

 

When your code says cellwidth=1in then that is what you get, a cell of one inch width. You could take a pass through your data calculating the maximum number of characters per column, estimate a width using that information, stuff that into a bunch of macro variables and use those instead of literal 1in or similar values.

 

BUT if you are writing to a spreadsheet then the width of a specific cell may well be controlled by something well before the cell you are looking at.

Also if you are using a destination that actually has page widths such as RTF or PDF then your defined column widths may make the table split in some odd manner.

Contributor
Posts: 38

Re: Autofit column width in proc print

What destination are you printing to? What application is that screen shot from?

I'm using jupyter notebook connected to SAS, but I'm hoping that isn't relevant.

When your code says cellwidth=1in then that is what you get, a cell of one inch width. You could take a pass through your data calculating the maximum number of characters per column, estimate a width using that information, stuff that into a bunch of macro variables and use those instead of literal 1in or similar values.

I understand the implications of cellwidth=1in, I should have used another code. I've updated the question to remove this issue.

Super User
Posts: 12,148

Re: Autofit column width in proc print

Posted in reply to Autotelic

I have zero experience with Jupyter but I suspect that has a big part in this appearance as I can't generate any output like that in HTML, Listing, RTF of PDF. Many years ago I did make similar output using the OVERPRINT options with PUT statements when writing to a printer or embedding codes in data to make a printer do that.

 

It might help to provide a small data set and any other options you are using to see if any other Jupyter users have suggestions.

Ask a Question
Discussion stats
  • 4 replies
  • 105 views
  • 0 likes
  • 3 in conversation