BookmarkSubscribeRSS Feed
daradanye
Obsidian | Level 7

Hello,

 

I have a number of excel files named as file_a, file_b  until file_h.  I'd like to use a macro do loop to import the files.

 

Following the code in this link

I write the following code.  I also tried to add % before proc import command and it does not work either.  That would be great if someone can help here.

 

Thanks.

 


%let list = a b c d e f g h;
%local i next_name;
%let i=1;
%do %while (%scan(&list, &i) ne );
   %let next_name = %scan(&list, &i);
 proc import out=jobpost&next_name
	datafile="H:\bdata\file_&next_name..csv"
	dbms='' replace;
	run;
   %let i = %eval(&i + 1);
%end;
1 REPLY 1
Kurt_Bremser
Super User

A %DO must be part of a macro, you cannot use it in "open code".

If the csv files (which are NOT Excel files) have the same structure, you can read them in one DATA step.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 376 views
  • 0 likes
  • 2 in conversation