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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 11159 views
  • 2 likes
  • 3 in conversation