DATA Step, Macro, Functions and more

How to fix truncated fields in Excel even if the length is set to maximum?

Reply
Contributor
Posts: 54

How to fix truncated fields in Excel even if the length is set to maximum?

Hi all,

I've been trying to import an TEST.XLSX file using below code:

/***************************/

libname samp excel "TEST.XLSX" dbMax_text=32767 stringdates=YES scan_timetype=YES;

data work.Data_Step;

set samp."CSR$"n

(dbSasType= (ext_notes='CHAR(32767)') dbmax_text=32767);

run;

libname samp clear;

/***************************/

Despite setting the maximum lengths, I found that the field ext_notes is still truncated, but the length of the column is maximum.

When I use SAS EG Import Wizard to import the said excel file, the field ext_notes is not truncated. Perhaps there is a hidden special character here which causes the truncation?cia

Super User
Super User
Posts: 7,401

Re: How to fix truncated fields in Excel even if the length is set to maximum?

Whilst Excel can have 32767 characters per cell, I believe SAS is limited to how many characters per column.  I would suggest you do a text to columns in Excel and split the data up.  Then export to CSV and write a datastep import to ensure you get what you want.  https://support.microsoft.com/en-us/kb/214261/

Contributor
Posts: 54

Re: How to fix truncated fields in Excel even if the length is set to maximum?

Hi RW9,

Thank you for the response.

SAS produced one cell of the affected field at just 200 characters as displayed in the table.

However, that cell is actually just 1000 characters. The cell has already been truncated even though it hasn't reached the maximum SAS length.

Super User
Super User
Posts: 7,401

Re: How to fix truncated fields in Excel even if the length is set to maximum?

Yes, another delightful artifact of working with Excel.  As I always suggest, best method is to save as CSV, then write a datastep to read the data in.  Excel is not a data transport tool and there a numerous issues with using it.  Personally I wasn't that impressed with the libname statement, not because of the tech, but just the interaction between a structured format software and an unstructured file format such as Excel.  You wouldn't for instance enter data into Word and then try to read that in would you?

Super User
Posts: 6,936

Re: How to fix truncated fields in Excel even if the length is set to maximum?

Don't be too optimistic. I've had users who stored their SAS programs as .doc.

"There are only two infinite things, the universe and human stupidity. And I'm not so sure about the universe."

Albert Einstein

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 9,681

Re: How to fix truncated fields in Excel even if the length is set to maximum?

You could try scantext= option in proc import .

Ask a Question
Discussion stats
  • 5 replies
  • 702 views
  • 0 likes
  • 4 in conversation