BookmarkSubscribeRSS Feed
ChrisNZ
Tourmaline | Level 20

Here is a table with variables that contain values of random lengths and random number of lines. 
Q: Is there a way to export this to Excel from SAS so all values are visible inside a cell?

No wrapping, one line per value, cell width not that important.

It seems that ever since option autofit_height  was removed, nothing works?
The EOL delimiter can be changed

data HAVE;
  x = catx( '0D0A'x, '0000000000', '4445566778','9999999999','9991123456'); 
run;

ods excel file="&wdir\print.xlsx" options(sheet_name='Test');          
  proc print data=HAVE noobs ;
  run;
ods excel close;

Setting cellwidth to force line wrapping as sometimes suggested does not look like a solution since it breaks lines randomly rather than where required.

 

5 REPLIES 5
Ksharp
Super User

Chris,

You could try option "tagattr=“ to avoid  wrapping  a line when you want to outpu an excel file.

Here is an example:

 

data HAVE;
  x = catx( '0D0A'x, '0000000000', '4445566778','9999999999','9991123456'); 
run;

ods excel file="c:\temp\print.xlsx" options(sheet_name='Test');          
  proc report data=HAVE nowd ;
  columns x;
  define _all_/display style={tagattr="wrap:no"};
  run;
ods excel close;
ChrisNZ
Tourmaline | Level 20

Thank you @Ksharp !

Sadly this doesn't expand the row height. 

Excel actually behaves weirdly (this might be a company setup issue):

When I open the file, all values are in one row. Then I click on the cell, then on the formula bar and the cell changes to only display the top row.

 

In any case I cannot see the list of values because the row height is still the default height.

Ksharp
Super User

Chris,

Could you adjust it by hand ? Just click this button when you tap a cell.

Ksharp_0-1781161154884.png

 

LinusH
Tourmaline | Level 20

With some trial and error and AI conversation, I got all lines visible from your example:

data HAVE;
  x = catx( '0A'x , '0000000000', '4445566778','9999999999','9991123456'); 
run;

ods excel file="print.xlsx" options(sheet_name='Test' 
												 flow="Tables" 
												 row_heights="0,0,0,0,0");          
  proc print data=HAVE noobs ;
  	var x / style(column)={width=2.5cm
                           vjust=top 
                           tagattr="wrap:yes"
                       };
  run;
ods excel close;

But as you can guess, the setting of width= needs to be correlate with the actual length of your strings, which probably will make this hard to use in every day applications....?

Data never sleeps
Tom
Super User Tom
Super User

What happens if you ask ODS itself to split the lines of text in the cells by using an ODS escape sequence?

data HAVE;
  x = catx( '(*ESC*)n' , '0000000000', '4445566778','9999999999','9991123456'); 
run;
filename xlsx '~/example.xlsx';
ods excel file=xlsx
 options(sheet_name='example' 
				flow="Tables" 
				)
;          
proc print data=have noobs;
run;
ods excel close;

That seems to come close when I open the XLSX file in Numbers application.

Screenshot 2026-06-11 at 2.29.34 PM.png

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 179 views
  • 1 like
  • 4 in conversation