BookmarkSubscribeRSS Feed
mgrd
Calcite | Level 5

Hi, I'd like to import some columns from .XLSX file into SAS. I've tried some code posted in the communities but doesn't work! Any idea?

Thanks. 

11 REPLIES 11
Kurt_Bremser
Super User

Just do a simple import, and then use a keep statement to keep only the columns you want.

 

And give some information about what "doesn't work".

Post the code and log containing error messages, structure of dataset as was expected and as came out eventually.

mgrd
Calcite | Level 5

Hi KurtBremser,

 

I´ve used the codes below to import xlsx files, but the code gives error.

 

Code:

 PROC IMPORT datafile='Z:\Programs\file.xlsx'

       OUT=test DBMS=excel replace;

    sheet='dw_names;

RUN;

Error: ERROR: DBMS type EXCEL not valid for import.

 

Code: 

PROC IMPORT datafile='Z:\Programs\file.xlsx'

       OUT=test DBMS=xlsx replace;

    sheet='dw_names;

RUN;

Error: ERROR: DBMS type EXCEL not valid for import.

 

Do you have some idea to solve this?

Thanks in advance.

mgrd
Calcite | Level 5

Version 5.1 (32-bit)

 

Operating System:   WX64_WKS.

Kurt_Bremser
Super User

SAS version 5.1 (if there ever was one in production) would be over 30 years old and never work on any Windows. You probably mistook the Enterprise Guide version for this.

If your EG is 5.1, then you have at least SAS 9.2 as the workspace server. This still means that you have a problem with SAS/ACCESS to PC Files.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As an alternative to proc import:

libname myxlsx xlsx "c:\anxlsxfile.xlsx";

data want;

  set myxlsx.sheet1 (keep=var1 var2...);

run;

libname myxlsx clear;

mgrd
Calcite | Level 5

Dear RW9, I've tried your solution but doesn't work, with the error below: 

 

GOPTIONS ACCESSIBLE;

 

libname myxlsx xlsx "C:\Desktop\Imparidade\Test_Excel.xlsx";
ERROR: The EXCEL engine cannot be found.
ERROR: Error in the LIBNAME statement.

 

Tks

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Are you using SAS 9.2?  If so you can't use libname xlsx on that version;

http://support.sas.com/kb/49/468.html

 

You will have to go with the proc import as @Kurt_Bremser kindly provided, or alternatively, save as CSV and write a datastep import - which to my mind would be a far more robust method.

mgrd
Calcite | Level 5

Hi RW9,

I've test your suggestion but without success. Could you please have a look to error?

 

Code:

libname myxlsx  “Z:\Programs\file.xlsx”;

data want;

  set myxlsx.auto_dw_reportdetalhado (keep=CFK WF);

run;

libname myxlsx clear;

Error:

ERROR: The EXCEL engine cannot be found.

ERROR: Error in the LIBNAME statement.

18         data want;

19           set myxlsx.auto_dw_reportdetalhado (keep=CFK WF);

ERROR: Libname MYXLSX is not assigned.

20         run;

 

Thanks,

MD

Reeza
Super User

You can't selectively import data, but you can choose to not keep the variables or drop them in a further step.

 

 

Ksharp
Super User

Use RANGE= option .

Also you could try other dbms:

dbms=excel 

dbms=xlsx

 

proc import datafile='/folders/myfolders/edu.xls' out=have dbms=xls replace;
range='Sheet1$:A1:F10';
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 11 replies
  • 4728 views
  • 0 likes
  • 5 in conversation