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;
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.