Home » excel » excel – Error in the LIBNAME statement sas

excel – Error in the LIBNAME statement sas

Posted by: admin May 14, 2020 Leave a comment

Questions:

I want to import a database of excel to SAS, I use the correct commands but SAS tells me the following errors:

ERROR: Connect:
ERROR:Error in the LIBNAME statement sas

libname dir  'E:\SAS\sessio2\dades';
proc import out=dir.m
datafile="E:\SAS\sessio2\dades\matrimonios.xlsx"
DBMS=excel 
replace;
RANGE="Hoja1$A1:AJ54"; 
getnames=yes;
run; 
How to&Answers:

As Yick says, the error is in your PROC IMPORT statement. Behind the scenes PROC IMPORT creates a LIBNMAE statement using the EXCEL engine.

Some things that might be wrong:

  • If your version is prior to 9.1.3, I don’t think you cannot read the
    new xlsx format. Save the file in the old format and try again.
  • Make sure you have specified the proper file and path.
  • Make sure you have the range specified properly.
  • The Range statement can be hinky. Try specifying the SHEET= option
    instead.
  • Make sure you have ACCESS/PC Files licensed.

Answer:

I’m not sure if it’s your libname statement path that is incorrect or the version of your SAS. if you’re using datafile= "path.xlsx", then try using DBMS=.xlsx as well.

If that doesn’t work, perhaps try changing datafile= from .xlsx to .xls I’m not sure which version of SAS you have.

But in 9.1.3 it’s better to use .xls If your excel file is in .xlsx, just open it and save as 2003 .xls version. Your code seems to work fine on my computer but that’s using my own excel file.

libname dir  'C:\sasdata';
proc import out=dir.m
datafile="C:\sasdata\sfosch.xls"
DBMS=excel 
replace;
*RANGE="Hoja1$A1:AJ54"; 
getnames=yes;
run;