stringimportsasprocimport-from-excel

How to get complete text string(large) using SAS Proc Import


I am trying to get data from xlsx file using Proc Import procedure and it was successful but when i look into the data. The variable doesn't have the complete text value and length of that variable is fixed to $255. How to get Full Text value?

PROC IMPORT DATAFILE= "C:\comments.xlsx" 
 OUT= WORK.comments
 DBMS=XLSX
 REPLACE;
 SHEET="Sheet1"; 
 GETNAMES=YES;
RUN; 

Solution

  • PROC IMPORT can definitely handle strings longer than 255. You can run a test yourself to see it.

    filename xlsx temp;
    data test ;
      length len 8 string $2000 ;
      string = repeat('0123456789',199);
      len = length(string);
    run;
    
    proc export file=xlsx dbms=xlsx data=test;
    run;
    
    proc import file=xlsx dbms=xlsx out=test2 replace;
    run;
    
    proc compare data=test compare=test2;
    run;
    

    Make sure to check the PROC CONTENTS results for the imported datasets. For example make sure you have not attached too short a display format to the variable.

    You can also try using the XLSX libname engine instead of PROC IMPORT to read from the XLSX file, but I doubt it will yield different results.

    libname mylib xlsx "C:\comments.xlsx" ;
    data comments;
      set mylib.Sheet1;
    run;
    

    If you cannot get your file to work then you should open a support ticket with SAS Support so they can examine your XLSX file.