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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2964 views
  • 4 likes
  • 6 in conversation