<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Macro doesn't update variables after argument parsing in do loop in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-doesn-t-update-variables-after-argument-parsing-in-do-loop/m-p/589981#M14981</link>
    <description>&lt;P&gt;Hi, I have issues with running a macro in a do loop.&lt;BR /&gt;&lt;BR /&gt;I have the following macro which works on its own:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_excel(path,year,month, sheetname);
%put &amp;amp;path.\CRT&amp;amp;year.\&amp;amp;month.&amp;amp;year..xlsx;

proc import out=CRT_&amp;amp;year._&amp;amp;month.
datafile="&amp;amp;path.\CRT&amp;amp;year.\&amp;amp;month.&amp;amp;year..xlsx"
dbms = xlsx replace; 
sheet="&amp;amp;sheetname.";

data CRT_&amp;amp;year._&amp;amp;month.; 
set CRT_&amp;amp;year._&amp;amp;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 = "&amp;amp;year.";
month = "&amp;amp;month.";

run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to iterate over years and months like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%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);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It does work without problems. However I am looking for a more elegant solution:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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, '&amp;amp;i.', '&amp;amp;m.' ,RawData));
	end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, it does not update the datafile="&amp;amp;path.\CRT&amp;amp;year.\&amp;amp;month.&amp;amp;year..xlsx" at all and nothing works afterwards.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Sep 2019 10:48:27 GMT</pubDate>
    <dc:creator>pkopersk</dc:creator>
    <dc:date>2019-09-19T10:48:27Z</dc:date>
    <item>
      <title>Macro doesn't update variables after argument parsing in do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-doesn-t-update-variables-after-argument-parsing-in-do-loop/m-p/589981#M14981</link>
      <description>&lt;P&gt;Hi, I have issues with running a macro in a do loop.&lt;BR /&gt;&lt;BR /&gt;I have the following macro which works on its own:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_excel(path,year,month, sheetname);
%put &amp;amp;path.\CRT&amp;amp;year.\&amp;amp;month.&amp;amp;year..xlsx;

proc import out=CRT_&amp;amp;year._&amp;amp;month.
datafile="&amp;amp;path.\CRT&amp;amp;year.\&amp;amp;month.&amp;amp;year..xlsx"
dbms = xlsx replace; 
sheet="&amp;amp;sheetname.";

data CRT_&amp;amp;year._&amp;amp;month.; 
set CRT_&amp;amp;year._&amp;amp;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 = "&amp;amp;year.";
month = "&amp;amp;month.";

run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to iterate over years and months like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%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);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It does work without problems. However I am looking for a more elegant solution:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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, '&amp;amp;i.', '&amp;amp;m.' ,RawData));
	end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, it does not update the datafile="&amp;amp;path.\CRT&amp;amp;year.\&amp;amp;month.&amp;amp;year..xlsx" at all and nothing works afterwards.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 10:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-doesn-t-update-variables-after-argument-parsing-in-do-loop/m-p/589981#M14981</guid>
      <dc:creator>pkopersk</dc:creator>
      <dc:date>2019-09-19T10:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro doesn't update variables after argument parsing in do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-doesn-t-update-variables-after-argument-parsing-in-do-loop/m-p/589986#M14982</link>
      <description>&lt;P&gt;First of all, you have invalid quote symbols in your code, probably caused by using improper editing software (do NOT use word processors for code).&lt;/P&gt;
&lt;P&gt;Second, and more important, the macro trigger is resolved when the data step is &lt;EM&gt;compiled,&lt;/EM&gt; so anything the data step does when it executes is irrelevant. Use call execute() if you want dynamic execution of macro calls:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%import_excel(C:\Users\a0782369\Desktop\testluk,',yrs,',',mth,',',RawData,'))'));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 11:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-doesn-t-update-variables-after-argument-parsing-in-do-loop/m-p/589986#M14982</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-19T11:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro doesn't update variables after argument parsing in do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-doesn-t-update-variables-after-argument-parsing-in-do-loop/m-p/589991#M14983</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/207645"&gt;@pkopersk&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition to the issue with the macro calls resolving to invalid syntax (like "PROC step in a DATA step"), as pointed out by Kurt Bremser, your LENGTH statement should use the DATA step variable MTH, not the macro variable M in order to avoid truncation of the month names (longer than "janvier"). Personally, I would avoid national language characters in SAS names (my SAS version didn't even tolerate the accented characters in dataset names). You can use the &lt;A href="https://documentation.sas.com/?docsetId=nlsref&amp;amp;docsetTarget=p078j5y1bbc9xfn1scp11kw3nmnt.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;BASECHAR function&lt;/A&gt;&amp;nbsp;for an easy conversion:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length mth $9;
do yrs = 2018 to 2019;
  do mth = 'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre','décembre';
    call execute(catx(',','%nrstr(%import_excel(C:\Users\a0782369\Desktop\testluk',yrs,basechar(mth),'RawData))'));
  end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 11:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-doesn-t-update-variables-after-argument-parsing-in-do-loop/m-p/589991#M14983</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-09-19T11:59:56Z</dc:date>
    </item>
  </channel>
</rss>

