BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cbal324
Calcite | Level 5

Hello,

I am wondering if anyone can provide guidance on an issue I have encountered when using PROC PRINT to print tables into an Excel format (via ODS).  It pertains to the header rows.  I am running SAS 9.2.

On occasion, some of my headers spill onto a second row, as observed when exporting to Excel, despite the fact that I am NOT specifying a split= character.  As one example, I have some SAS output (exported to Excel) in which the label for the last column is split between two rows.  For purposes of copying and pasting this data into a separate standard delivery template, it would be preferable for all labels to always fit within a single row without wrapping.

My PROC PRINT code is as follows - pretty basic.

proc print data = final label noobs;

  format distpercentchange countpercentchange percentn10.1 count1 count2 comma10.;

  var rankcirc mfrname distpercentchange count1 count2 countpercentchange;

  label rankcirc = 'Rank'

        mfrname = 'Manufacturer'

        distpercentchange = "&period YOY % Change"

        count1 = "&lastyear Offer Count"

        count2 = "&thisyear Offer Count"

        countpercentchange = "Offer Count YOY % Change";

run;

Are there any thoughts as to whether there are any options or alternative methods that I can consider using to force my headings onto a single row?  Is there any other information that I can provide?

Thanks very much!

Chris

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

I can recreate your problem using SASHELP.CLASS.

proc print data=sashelp.class label noobs ;

  label name='This label is longer than the column width';

run;

Why not just use PROC EXPORT to write an XLS (or better XLSX) file directly from the data instead of using PROC PRINT?

Or write a real (or at least closer to real) Excel file by using ODS tagsets.excelxp or the new ODS Excel .

Or use a proc like PROC REPORT that will let you specify the column width and the data format separately.

View solution in original post

5 REPLIES 5
ballardw
Super User

How are you exporting to Excel? Tagsets.Excelxp or HTML and opening in Excel or something else?

The ods settings do have an impact on choices.

cbal324
Calcite | Level 5

Thank you for the response!  Good question - for this, I am simply using HTML and opening in Excel.

ods html file = "G:\path\filename.xls";

* proc print, etc.;

ods html close;

Tom
Super User Tom
Super User

I can recreate your problem using SASHELP.CLASS.

proc print data=sashelp.class label noobs ;

  label name='This label is longer than the column width';

run;

Why not just use PROC EXPORT to write an XLS (or better XLSX) file directly from the data instead of using PROC PRINT?

Or write a real (or at least closer to real) Excel file by using ODS tagsets.excelxp or the new ODS Excel .

Or use a proc like PROC REPORT that will let you specify the column width and the data format separately.

Cynthia_sas
SAS Super FREQ

Hi:

  The main issue is that Excel will not like the column widths if you use ODS and will "pick" a general column width. And, I believe it does this with the EXPORT method too. I do have some other suggestions:

       

1) if you are creating output for Excel, I recommend using ODS MSOFFICE2K as the destination. Microsoft did not agree with the standard HTML 4.0 specification (which is what ODS HTML creates) and the ODS MSOFFICE2K destination creates the kind of HTML tags that conform to Microsoft HTML

   

2) You can explicitly change the width of the cells so that the header has more room:

proc print data = xxxxx.yyyyy label noobs

  style(data)={width=2in};

  var onevar twovar;

  var redvar bluevar / style(data)={width=1.5in};

run;

proc report data = xxxxx.yyyyy nowd

  style(column)={width=2in};

  column onevar twovar redvar bluevar;

  define redvar / style(column)={width=1.5in};

  define bluevar / style(column)={width=1.5in};

run;

3) I have more about overriding Excel defaults in this paper:https://support.sas.com/resources/papers/proceedings11/266-2011.pdf  (covers leading zeroes, column width, decimal points, percent signs, etc)

cynthia

cbal324
Calcite | Level 5

All -

Thank you for your assistance on this!  I found that in my particular case, explicitly changing the cell widths within PROC PRINT still did not result in the desired output.  Even after shrinking the font size for good measure, one of my headings insisted on wrapping onto two rows despite having an abundance of space to fit onto one.

It turns out that for my specific needs, PROC REPORT provides a little more versatility with regard to customizing my output.  After simply converting my PROC PRINT step into a PROC REPORT step, the headings appear exactly as desired while the data itself is shown exactly as it was before.  So my very quick and easy solution will be to use PROC REPORT for my exports to Excel.

proc report nowd data = final;

   column rankcirc mfrname distpercentchange count1 count2 countpercentchange;

   define rankcirc / "Rank";

   define mfrname / "Manufacturer";

   define distpercentchange / format=percentn10.1 "&period YOY % Change";

   define count1 / format=comma10. "&lastyear Offer Count";

   define count2 / format=comma10. "&thisyear Offer Count";

   define countpercentchange / format=percentn10.1 "Offer Count YOY % Change";

run;

Thanks again for all of the great suggestions!

Chris

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 4381 views
  • 6 likes
  • 4 in conversation