BookmarkSubscribeRSS Feed
rajd1
Quartz | Level 8

I have a couple of variables that have long text data in excel. When I import it with import statement it stops at 175 characters. I want to be able to get full text length.

PROC IMPORT OUT= WORK.ge DATAFILE= "filepath/name"

DBMS=xlsx REPLACE;

SHEET="One";

GETNAMES=YES;

RUN;

Thank you

7 REPLIES 7
hyo_tree
Fluorite | Level 6
Hi rajd1,

please give the length of the variable you want to store the long text. Because SAS will default that the length of this variable is the length of the first data value you entered.
Don’t stop pursuing to be a better version of yourself, even if only a little change
Patrick
Opal | Level 21

@hyo_tree wrote:
Hi rajd1,

please give the length of the variable you want to store the long text. Because SAS will default that the length of this variable is the length of the first data value you entered.

@hyo_tree This statement is not correct. Proc Import with the XLSX engine will use the longest string to assign the variable length.

 

@rajd1 

Below code reads the attached Excel where the longest string for column VarA is in cell A5000 - and it gets it right.

What happens on your end if you use this code to read the attached Excel?

 

proc import 
  out= work.ge 
  datafile= "~/test/test.xlsx"
  dbms=xlsx 
  replace;
  sheet="one";
  getnames=yes;
run;

proc contents data=work.ge;
run;quit;

Capture.JPG

 

hyo_tree
Fluorite | Level 6
thank you . I got it.
Don’t stop pursuing to be a better version of yourself, even if only a little change
Ksharp
Super User
or Try:
libname x xlsx 'c:\...' dbmax_text=32767;
newsas007
Quartz | Level 8
Thank you this worked

libname db "C:\excel files\test1.xls" mixed=yes;
data test3;
set db."Sheet1$"n(DBSASTYPE=(var='char(1024)'));
run;
libname db;
smantha
Lapis Lazuli | Level 10
Please try scantext option.
SCANTEXT applies to columns containing text. If SCANTEXT=YES, then SAS will scan the column for the longest string, and uses its length as the column width.
newsas007
Quartz | Level 8
The Scantext option did not work.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7 replies
  • 2760 views
  • 4 likes
  • 6 in conversation