BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

Hello Experts,
Is it possible to access the range in xlsm file using Libname xls? 

My code is working:

 

options validvarname=any;


libname xl XLSX "\\XXX\TousIsin.xlsm";

data isin;
set xl.'VALEURS$B2:50'n;
run;


BUT when I replace B2:50 by range NAME:

 

data isin;
set xl.'VALEURS$test'n;
run;

 

My code doesn'y work. 😞


Thank you for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

I'll recap what we know so far:

  • from the path, your SAS runs on Windows
  • you have ACCESS to PC Files licensed, as LIBNAME XLSX works
  • LIBNAME EXCEL or XLS gets the "class not registered" error

You either have a the necessary ACE or JET engine not available, or a bitness problem. See this SAS Note for possible remedies: https://support.sas.com/kb/63/750.html 

View solution in original post

10 REPLIES 10
Oligolas
Barite | Level 11

Hi,

Seems like you've tested it.

AFAIK you'll need the libname excel

libname xlfile excel "your xlsm file" access=read;
proc print data=sashelp.vtable (keep=libname memname memtype);
where libname eq 'XLFILE';
run;
________________________

- Cheers -

SASdevAnneMarie
Barite | Level 11
Thank you,
It doesn't work:
ERROR: Connect: Classe non enregistrée
ERROR: Error in the LIBNAME statement.

I would like to import the range from xlsm file.
Kurt_Bremser
Super User

Did LIBNAME XLS (which you previously mentioned) actually work? This looks as if you do not have ACCESS to PC Files licensed or installed, or are running SAS on a non-Windows platform.

SASdevAnneMarie
Barite | Level 11
Hello Kurt,

This code is working:



options validvarname=any;


libname xl XLSX "\\XXX\TousIsin.xlsm";

data isin;
set xl.'VALEURS$B2:50'n;
run;


BUT when I replace B2:50 by range NAME:



data isin;
set xl.'VALEURS$test'n;
run;



My code doesn'y work. 😞
Kurt_Bremser
Super User

Run this:

libname xl XLSX "\\XXX\TousIsin.xlsm";

proc sql;
select memname from dictionary.tables where libname = "XL";
quit;

and look at the dataset names you get in the library.

SASdevAnneMarie
Barite | Level 11
Thank you,
I have the datasets with page name (the data by page), not by range.
SASdevAnneMarie
Barite | Level 11
I mean that my ranges are named, I didn’t se tables by range.

Thank you
Kurt_Bremser
Super User

A little research revealed that the XLSX engine does not support named ranges, so you have (AFAIK) three options:

  • use LIBNAME EXCEL. Works only on Windows, and SAS and Office (installed on the SAS host) must be of the same bitness (32/64)
  • LIBNAME XLS, with the same restrictions regarding bitness (AFAIK)
  • use the PC Files Server and the EXCELCS engine.
Kurt_Bremser
Super User

I'll recap what we know so far:

  • from the path, your SAS runs on Windows
  • you have ACCESS to PC Files licensed, as LIBNAME XLSX works
  • LIBNAME EXCEL or XLS gets the "class not registered" error

You either have a the necessary ACE or JET engine not available, or a bitness problem. See this SAS Note for possible remedies: https://support.sas.com/kb/63/750.html 

Oligolas
Barite | Level 11

Hi,

 

it looks like you haven't SAS/ACCESS licensed.

You could try with proc Import but I think it won't work neither since it listed in the SAS/ACCESS Interface to PC Files but I would give it a try.

PROC IMPORT OUT= WORK.want 
            DATAFILE= "C:\fileWithNamedRanges.xlsm" 
            DBMS=EXCEL REPLACE;
            RANGE="range1"; 
            GETNAMES=YES;
            MIXED=YES;
            SCANTEXT=YES;
            USEDATE=YES;
            SCANTIME=YES;
RUN;

If none of the proposals work, maybe you can use some vba code to export a named ranges to a new xlsx workbook and Import the data.

I wasn't aware that what you posted before actually works, so thanks for this 🙂

libname xl XLSX "\\XXX\TousIsin.xlsm";
data isin;
set xl.'VALEURS$B2:50'n;
run;
________________________

- Cheers -

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 1573 views
  • 2 likes
  • 3 in conversation