BookmarkSubscribeRSS Feed
angeliquec
Quartz | Level 8

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

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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/

angeliquec
Quartz | Level 8

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

Kurt_Bremser
Super User

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

Ksharp
Super User

You could try scantext= option in proc import .

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5971 views
  • 0 likes
  • 4 in conversation