Hi, I have issues with running a macro in a do loop.
I have the following macro which works on its own:
%macro import_excel(path,year,month, sheetname);
%put &path.\CRT&year.\&month.&year..xlsx;
proc import out=CRT_&year._&month.
datafile="&path.\CRT&year.\&month.&year..xlsx"
dbms = xlsx replace;
sheet="&sheetname.";
data CRT_&year._&month.;
set CRT_&year._&month.;
/* If numeric imported as character, then convert to numeric*/
array chars {*} _character_;
do _n_ = 1 to dim(chars);
chars{_n_} = put(chars{_n_},BEST18.);
end;
year = "&year.";
month = "&month.";
run;
%mend;
Then,
I try to iterate over years and months like this:
%import_excel(C:\Users\a0782369\Desktop\testluk, 2018,janvier,RawData);
%import_excel(C:\Users\a0782369\Desktop\testluk, 2018,février,RawData);
%import_excel(C:\Users\a0782369\Desktop\testluk, 2019,janvier,RawData);
%import_excel(C:\Users\a0782369\Desktop\testluk, 2019,février,RawData);
It does work without problems. However I am looking for a more elegant solution:
data _NULL_;
length m $20;
do yrs = 2018 to 2019;
call symput('i',yrs);
do mth = 'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre','décembre' ;
call symput('m',mth);
%import_excel(C:\Users\a0782369\Desktop\testluk, '&i.', '&m.' ,RawData));
end;
end;
run;
However, it does not update the datafile="&path.\CRT&year.\&month.&year..xlsx" at all and nothing works afterwards.
Thank you.