title: Writing a loop within a macro in SAS
body: <p>What is wrong with my program below? I am trying to import several excel files and merge them.
  Rename does not work in the import step. More importantly, merge does not work even if datasets y1 and y2 are created.
  Thanks.</p>
  
  <pre><code>proc sort data=sourceh.caps;
  by symbol;
  run;
  
  %MACRO RunProgram(month, year, n);
  
  PROC Import DATAFILE= "D:\new\&amp;month. &amp;year. &amp;n. min correlations.xls" 
     dbms=excel5  OUT= sourceh.y&amp;n. (rename=(avcorr=y&amp;n.))  replace;
      GETNAMES=YES;
  RUN;
  
  
  data sourceh.testy&amp;month.&amp;year.;
  merge sourceh.y&amp;n. sourceh.caps;
  by symbol;
  drop number;
  Month="&amp;month.";
  Year=&amp;year.;
  run;
  
  %MEND;
  
  %macro l;
  
  %do n=1 %to 2;
  
  %RunProgram(Jan, 12, &amp;n);
  %RunProgram(Apr, 12, &amp;n);
  
  %end;
  
  %mend;
  
  %l;
  </code></pre>