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

Hi,

 

In a given catalogue, I have a number of xlsm files that I want to import to SAS using libname excel. The files are named sales_2013.xlsm, sales_2014.xlsm etc.

 

I've tried the following loop

 

 

options mprint mlogic symbolgen;
%macro set_libname;
%do i=2013 %to 2016;
	options validvarname=any validmemname=extend;
	libname scen&i excel "C:\Data\sales_&i.xlsm" access=read;
%end;
%mend;
%set_libname; 

However, the code produces the following error: "ERROR: ERROR: File extension specified is invalid". In the log I can see that SAS resolves the path to e.g. "C:\Data\sales_2013". So, it ignores the ".xlsm" extension, which - I guess - causes the problem.

 

How can I fix it?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Note that a dot is used to terminate macro variable names, which is especially needed when macro variables are used within a string:

libname scen&i excel "C:\Data\sales_&i..xlsm" access=read;

The first dot terminates the variable call &i, the second one will appear in the resulting filename.

 

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

Note that a dot is used to terminate macro variable names, which is especially needed when macro variables are used within a string:

libname scen&i excel "C:\Data\sales_&i..xlsm" access=read;

The first dot terminates the variable call &i, the second one will appear in the resulting filename.

 

chris2377
Quartz | Level 8
Thanks a lot. It's working now
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Perhaps another Maxim is needed, 

Always use the dot after macro variables!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 12478 views
  • 2 likes
  • 3 in conversation