BookmarkSubscribeRSS Feed
Shtag
Calcite | Level 5

I'm a novice SAS user and I am having an issue with an exported Excel workbook.

 

The file is 1.47MB when extracted, but another program errors out when reading it.  Once I open the file and do nothing other than hit save, it expands to 1.8MB and the other program is then able to read it.  I checked with a colleague who runs a larger daily report and it turns out his report does the same thing - expands once saved - so it's not unique to me it seems.  (It's not a problem for him as his report goes to a human user who has no problem opening the file.)  One thing I've considered is that I'm running 64-bit Windows and SAS EG but 32-bit Excel, but I'm not sure if that would cause this type of behaviour.

 

I've tried dbms=excel and xls, I've tried to use xlsb, but with my level of experience I'm really just feeling around in the dark.

 

EDIT - Sorry I didn't make the problem clear: I want the other program (a web-based mapping tool) to be able to read the Excel file without the user having to manually save it in Excel first.  For whatever reason, it can read the 1.8MB saved file but not the 1.47MB extracted file.

 

Below is the relevant part of the code. Any advice would be appreciated!

 

Proc export data=WORK.Table1
Outfile="/path/filename.xlsx"
dbms=xlsx replace; sheet=Table1;
RUN;

Proc export data=WORK.Table2
Outfile="/path/filename.xlsx"
dbms=xlsx replace; sheet=Table2;
RUN;

FILENAME Mailbox
EMAIL 'address'
CC='address'
Subject="Subject"
ATTACH=('/path/filename.xlsx' content_type="application/xlsx");

 

5 REPLIES 5
Tom
Super User Tom
Super User

I think that Excel saves redundant information when it saves the files. Perhaps your other program is following its experience of reading Excel generated XLSX files instead of following the specifications of how XLSX files are to be made.

 

Try making a small XLSX file with SAS.  Open it with Excel and save to a new file.  

XLSX files are just ZIP archives of a series of XML files.  So if you rename the files to use .ZIP instead of .XLSX as the extension you can look at the individual files inside of it. See if you can tell what Excel is changing.

Shtag
Calcite | Level 5

Thanks Tom I'll give this a try.

SASKiwi
PROC Star

So what exactly is your problem? That Excel when exported creates a larger workbook than the original?. Well welcome to the wonderful world of Excel then, where you have no way of locking down the size and data type of your columns so that they don't cause unexpected issues.

 

An easy workaround would be to export a CSV where you can explicitly set the size of your columns so it shouldn't grow in size. Excel can still read CSVs but you are limited to one sheet per workbook unfortunately.

Shtag
Calcite | Level 5

I don't mind about the size, but since the other program (a web-based mapping application) cannot read the smaller version I assumed the issues were related.  When I save it in Excel, it fixes whatever issue the mapping tool has with the file, and also inflates the file size.

 

The mapping tool doesn't like CSVs unfortunately.

 

The idea was that the file would auto-load - I'm trying to avoid the user having to open the file in Excel just to hit Save.  Currently that's the only way to make the mapping tool read the file correctly.

SASKiwi
PROC Star

Where does emailing the Excel file as an attachment come into it then? And I wouldn't necessarily assume that a file increase would cause the problem you are having. Examine the Excel worksheet, particularly the data types being used and compare them to the original.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register 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.

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
  • 660 views
  • 0 likes
  • 3 in conversation