<?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 Re: Running macro multiple times in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814089#M321337</link>
    <description>&lt;P&gt;Where do you have the list of values of DT?&lt;/P&gt;
&lt;P&gt;Is DT intended to be a character string like:&amp;nbsp; '&lt;SPAN&gt;201407'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Are number like:&amp;nbsp;201,407&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Or a date value like, 01JUL2014, that has been formated with the YYMMN6. format?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Or some other strange date like 14JUL2020?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do you want to generate the filename from the value of ID (or DT)?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So something like this will generate a dataset with one observation per ID value and also generate one call to the macro for each ID.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length id 8 filename $100;
  do id = 201407,201508,201605,201706,201804,201905;
    filename=cats('bnk_mkt_scr_',id,'.xlsx');
    call cxecute(catx(' '
         ,'%nrstr(%creating_data_tables)(out_tbl=abc,in_file='
         ,filename
         ,')'
     ));
     output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;If instead you already have the list of ID (or DT) values in a dataset then just use a data _null_ step instead.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have;
  filename $100;
  filename=cats('bnk_mkt_scr_',id,'.xlsx');
  call cxecute(catx(' '
       ,'%nrstr(%creating_data_tables)(out_tbl=abc,in_file='
       ,filename
       ,')'
   ));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 18 May 2022 14:59:18 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-05-18T14:59:18Z</dc:date>
    <item>
      <title>Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814083#M321332</link>
      <description>&lt;P&gt;I need to run macro call multiple times :&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;do id = dt ( for dt I have values like&amp;nbsp;201407,201508,201605,201706,201804,201905&amp;nbsp; got from another macro)&lt;/P&gt;&lt;P&gt;call execute(cats(%nrstr(%creating_data_tables(out_tbl = abc , in_file = bnk_mkt_scr_&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;dt&lt;/STRONG&gt;&lt;/FONT&gt;.xlsx) ;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;I want to call this macro for different values of yearmonth dates available in dt . I tried the above but didn't work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Kajal&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 14:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814083#M321332</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2022-05-18T14:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814087#M321335</link>
      <description>&lt;P&gt;Try adapting this code which runs successfully for me in order to rename variables over different tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let filesas=_201112servilease;
libname curr "%trim(&amp;amp;path2whole2)";
&amp;nbsp;
data _null_;
set dirxls;
call execute('%renamehelp (whole2._'||strip(file_name)||', f_fin&amp;nbsp;&amp;nbsp; , F_END); ');
run;
&amp;nbsp;
&amp;nbsp;
%macro renamehelp (sasf, oldN, newN);
&amp;nbsp;
data &amp;amp;sasf;
set &amp;amp;sasf (rename=(&amp;amp;oldN=&amp;amp;newN));
run;
&amp;nbsp;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 May 2022 14:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814087#M321335</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-05-18T14:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814088#M321336</link>
      <description>&lt;P&gt;A macro isn't needed here (maybe a macro variable is needed). A data step DO loop should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, the important advice if you're going to write a macro is to produce&amp;nbsp;&lt;STRONG&gt;working&amp;nbsp;&lt;/STRONG&gt;SAS code without macros and macro variables for this problem with just one or two dates. If you don't have working code&amp;nbsp;without macros and macro variables, then it will never work with macros or with macro variables. Most people ignore this advice, and their macro code never works. Don't ignore this advice. Show us working code without macros and without macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 15:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814088#M321336</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-18T15:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814089#M321337</link>
      <description>&lt;P&gt;Where do you have the list of values of DT?&lt;/P&gt;
&lt;P&gt;Is DT intended to be a character string like:&amp;nbsp; '&lt;SPAN&gt;201407'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Are number like:&amp;nbsp;201,407&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Or a date value like, 01JUL2014, that has been formated with the YYMMN6. format?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Or some other strange date like 14JUL2020?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do you want to generate the filename from the value of ID (or DT)?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So something like this will generate a dataset with one observation per ID value and also generate one call to the macro for each ID.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length id 8 filename $100;
  do id = 201407,201508,201605,201706,201804,201905;
    filename=cats('bnk_mkt_scr_',id,'.xlsx');
    call cxecute(catx(' '
         ,'%nrstr(%creating_data_tables)(out_tbl=abc,in_file='
         ,filename
         ,')'
     ));
     output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;If instead you already have the list of ID (or DT) values in a dataset then just use a data _null_ step instead.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have;
  filename $100;
  filename=cats('bnk_mkt_scr_',id,'.xlsx');
  call cxecute(catx(' '
       ,'%nrstr(%creating_data_tables)(out_tbl=abc,in_file='
       ,filename
       ,')'
   ));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 May 2022 14:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814089#M321337</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-18T14:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814094#M321338</link>
      <description>&lt;P&gt;Didn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quite often when using macros the first debug option is to set OPTIONS MPRINT before code that executes macro to se what the macro generates. The error messages, if any, will also then appear in closer proximity to code generating them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to confirm you did compile the macro in the current session before running the code, didn't you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code is sending a litteral dt to the macro where you highlight it. There is nothing that supplies values to the variable dt (on the right of the = sign) as you have no SET or similar statement to reference a data set to provide them. You are not using a macro variable as shown. You would have to show the actual value of the macro variable to have a chance of this working.&lt;/P&gt;
&lt;P&gt;If your&lt;/P&gt;
&lt;PRE&gt;id = dt ;/* note you did not have a ; to end the statement*/&lt;/PRE&gt;
&lt;P&gt;was supposed to be&lt;/P&gt;
&lt;PRE&gt;id = &amp;amp;dt;&lt;/PRE&gt;
&lt;P&gt;why does that statement exist? If your &amp;amp;dt macro variable contains multiple values that you intend to use one at a time then you need to get stuff from the macro and split it up, not copy it.&lt;/P&gt;
&lt;P&gt;Maybe something along these lines (depends a LOT on actual value of the not shown macro variable dt.&lt;/P&gt;
&lt;PRE&gt;data Junk;
 length longstr $ 200;
   Do i= 1 to countw("&amp;amp;dt.");
      dttemp = scan("&amp;amp;dt.",i);
      longstr = cats('%creating_data_tables(out_tbl = abc , in_file = bnk_mkt_scr_',dttemp,'.xlsx);');
      output;
      call execute(longstr);
   end;
run;&lt;/PRE&gt;
&lt;P&gt;Suggestion would be to run the above with the CALL Execute commented out so that it does not execute and examine the values of the LONGSTR variable to see if the code for the macro call is correct. If so, then uncomment the call execute. The test without call execute takes so little time you lose not much time compared to trying to figure out why all the executes you create are throwing errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="6" color="#FF0000"&gt;HINT: Your code as designed is very useless as the apparent output is reused and the result will only be the version for the last value of the dt variable. This is based on a macro parameter named OUT_TBL which I expect to be the desired result. You overwrite it with each execution of the macro.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 15:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814094#M321338</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-05-18T15:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814117#M321345</link>
      <description>&lt;P&gt;Here is my full macro definition :&lt;/P&gt;&lt;PRE&gt;libname output '/sas/out/data';

%macro creating_tables (out_table =
			,in_file  = 
			);
	PROC IMPORT 
		OUT= &amp;amp;out_table
		DATAFILE= "sas/repo/files/&amp;amp;in_file..xlsx" 
		DBMS=xlsx 
		REPLACE;
		GETNAMES=YES;
	RUN;

	DATA  &amp;amp;out_table;
		SET  &amp;amp;out_table;
		LOAD_TIME = datetime();
		yearmonth = "&amp;amp;yearmonth";
		FORMAT LOAD_TIME datetime20.;
	RUN;

	proc append base = output.&amp;amp;out_table
		data =   &amp;amp;out_table;
	run;

%mend creating_tables;&lt;BR /&gt;%creating_tables(out_table = Canada_bkn_score &lt;BR /&gt;,in_file = qtr_src_file_&amp;amp;yearmonth..xlsx&lt;BR /&gt;);&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;and I want to call this macro multiple times for different values of yearmonth. So I can have those values either stored in a macro variable or as a column value in a dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 16:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814117#M321345</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2022-05-18T16:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814122#M321347</link>
      <description>&lt;P&gt;Please see Tom's proposed solutions.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;You basically need either a dataset of file names, or you can use a DO loop to generate the date part of the file names.&lt;BR /&gt;&lt;BR /&gt;Be sure to use CALL EXECUTE like Tom showed, with %nrstr, and also single quote marks.&amp;nbsp; Your original post is missing single quote marks around the string passed as an argument to CALL EXECUTE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 16:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814122#M321347</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-18T16:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814132#M321356</link>
      <description>&lt;P&gt;I am getting below error after running the suggested code. But this macro call is running fine if I am running it out of data step i.e. not using call execute for one yearmonth.&lt;/P&gt;&lt;P&gt;ERROR: An exception has been encountered.&lt;BR /&gt;Please contact technical support and provide them with the following traceback information:&lt;BR /&gt;&lt;BR /&gt;The SAS task name is [IMPORT (]&lt;BR /&gt;Segmentation Violation&lt;BR /&gt;&lt;BR /&gt;Traceback of the Exception:&lt;BR /&gt;&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/sasexe/sas(+0x16840e) [0x55cea7c3c40e]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/sasexe/sas(+0x4eddf) [0x55cea7b22ddf]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/sasexe/tkmk.so(bkt_signal_handler+0x144) [0x2b9bf27a6ac4]&lt;BR /&gt;/usr/lib64/libpthread.so.0(+0xf630) [0x2b9bf1448630]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/sasexe/saswzsu(wzsdoff+0xa5) [0x2b9c0490f2c5]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/dbcs/sasexe/sasxkern(ypfmtc+0x11f) [0x2b9bffa18cef]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/dbcs/sasexe/sasxkern(+0x7dc5d) [0x2b9bffa2ac5d]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/dbcs/sasexe/sasxkern(ypslf+0xa54) [0x2b9bffa29c54]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/dbcs/sasexe/sasxkern(ypmpstr+0x2e3) [0x2b9bffa25343]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/dbcs/sasexe/sasxkern(ypmstr+0x9d) [0x2b9bffa2504d]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/dbcs/sasexe/sasyh(+0x385a9) [0x2b9c044395a9]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/dbcs/sasexe/sasyh(+0x377b7) [0x2b9c044387b7]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/dbcs/sasexe/sasyh(yyhlock+0x8e5) [0x2b9c04434d15]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/dbcs/sasexe/sasyoio(yddel3+0xaba) [0x2b9c38b6bc8a]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/dbcs/sasexe/sasyoio(yddel2+0x60) [0x2b9c38b6b1b0]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/sasexe/sasimctr(import+0x3f3) [0x2b9c5588d993]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/sasexe/sasimctr(parsexe+0x24b) [0x2b9c5588cb9b]&lt;BR /&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/sasexe/sasimpor(sasimpor+0x275) [0x2b9c55382df5]&lt;BR /&gt;3 The SAS System Wednesday, May 18, 2022 10:17:00 AM&lt;/P&gt;&lt;P&gt;/apps/sas/sashome/dev/cmp/SASFoundation/9.4/sasexe/sas(vvtentr+0x18a) [0x55cea7b2293a]&lt;BR /&gt;/usr/lib64/libpthread.so.0(+0x7ea5) [0x2b9bf1440ea5]&lt;BR /&gt;/usr/lib64/libc.so.6(clone+0x6d) [0x2b9bf1e908dd]&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 17:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814132#M321356</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2022-05-18T17:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814142#M321366</link>
      <description>&lt;P&gt;Not good.&lt;/P&gt;
&lt;P&gt;To debug that type of error run the PROC IMPORT step without any macro code involved.&lt;/P&gt;
&lt;P&gt;Start a new SAS session to run the test.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your code generation issue you will want to generate a different SAS dataset name for each XLSX file you read in.&amp;nbsp; Otherwise the datasets generated by the earlier calls to the macro will be overwritten.&amp;nbsp; One solution is to just include the YEARMONTH string into the name of dataset in addition to including it in the name of the XLSX file to be read.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 17:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814142#M321366</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-18T17:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814145#M321369</link>
      <description>&lt;P&gt;Proc import step is running fine out of macro.&lt;/P&gt;&lt;P&gt;secondly I tried running giving only yearmonth as macro variable name , in the log file names are resolving correctly but everything is getting replaced by last yearmonth call&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 17:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814145#M321369</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2022-05-18T17:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814148#M321372</link>
      <description>&lt;P&gt;You need to do something like this so that each PROC IMPORT step creates a different SAS dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yearmonth=202201;
proc import
  datafile="something or other&amp;amp;yearmonth..xlsx"
  out=something&amp;amp;yearmonth.
 ...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 May 2022 18:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814148#M321372</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-18T18:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814177#M321391</link>
      <description>&lt;P&gt;but when I am running this macro outside of the call execute keeping the same out = dataset name it is working absolutely fine.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 20:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814177#M321391</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2022-05-18T20:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814179#M321392</link>
      <description>&lt;P&gt;Please post:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Code where you run the macro 3 times, loading different excel files and it runs fine.&amp;nbsp; i.e. show the 3 macro invocations.&lt;/LI&gt;
&lt;LI&gt;Your current code where you use CALL EXECUTE to run the macro 3 times, and it does NOT work fine, but instead overwrites the output dataset.&lt;/LI&gt;
&lt;LI&gt;The log from running the above code (#1 and #2), with options MPRINT turned on.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the macro works when you write three macro calls, but does not work when generate three macro calls via CALL EXECUTE, then you are in good shape for debugging the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The challenge will be to get your CALL EXECUTE to the point where it can generate the exact same macro calls you are writing.&amp;nbsp; Assuming you are using %NRSTR() and single quotes on the CALL EXECUTE appropriately, the log should show the macro calls generated by CALL EXECUTE.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 20:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814179#M321392</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-18T20:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814180#M321393</link>
      <description>&lt;P&gt;Then either your macro is more complex than you have shown or you are doing other steps between the macro calls when you are running it manually.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 20:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814180#M321393</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-18T20:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814183#M321394</link>
      <description>&lt;P&gt;I think the problem is likely in the attempt to use CALL EXECUTE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro looks like it should work to me.&amp;nbsp; It writes (and over-writes) work.&amp;amp;out_table, then at the end PROC APPENDS it to out.&amp;amp;out_table.&amp;nbsp; It's bad style / risky to overwrite work.&amp;amp;out_table, but I think it should work when called three times in a row, including using CALL EXECUTE to generate the macro calls.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 20:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814183#M321394</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-18T20:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814184#M321395</link>
      <description>&lt;P&gt;Using PROC APPEND with dataset generated from PROC IMPORT is another source of errors as you cannot depend on PROC IMPORT creating compatible dataset structures.&amp;nbsp; But they would happen whether or not any code generation (macro call or CALL EXECUTE() function calls) was used to run the steps.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 20:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814184#M321395</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-18T20:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814297#M321419</link>
      <description>&lt;P&gt;This one is getting file name as&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;bnk_mkt_scr_201407,201508,201605,201706,201804,201905.xlsx'&lt;/LI-CODE&gt;&lt;P&gt;but we need it like individual files&amp;nbsp;&lt;/P&gt;&lt;P&gt;bnk_mkt_scr_201407.xlsx&lt;/P&gt;&lt;P&gt;bnk_mkt_scr_201508.xlsx and so on&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 14:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814297#M321419</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2022-05-19T14:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814300#M321421</link>
      <description>&lt;P&gt;That suggests the problem is with how you are using CALL EXECUTE.&amp;nbsp; Again, please show the CALL EXECUTE step you are running.&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 14:25:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814300#M321421</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-19T14:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814322#M321427</link>
      <description>&lt;P&gt;I am able to run that macro by manually putting multiple values for macro variables. but not able to loop macro variable values automatically.&lt;/P&gt;&lt;P&gt;for eg:&lt;/P&gt;&lt;P&gt;%let dt = 201901&lt;/P&gt;&lt;P&gt;%let dt = 201902&lt;/P&gt;&lt;P&gt;%let dt = 201903&lt;/P&gt;&lt;P&gt;%let dt = 201904&lt;/P&gt;&lt;P&gt;but I want it like to be resolved automatically each time of invocation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 16:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814322#M321427</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2022-05-19T16:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: Running macro multiple times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814326#M321428</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259983"&gt;@kajal_30&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am able to run that macro by manually putting multiple values for macro variables. but not able to loop macro variable values automatically.&lt;/P&gt;
&lt;P&gt;for eg:&lt;/P&gt;
&lt;P&gt;%let dt = 201901&lt;/P&gt;
&lt;P&gt;%let dt = 201902&lt;/P&gt;
&lt;P&gt;%let dt = 201903&lt;/P&gt;
&lt;P&gt;%let dt = 201904&lt;/P&gt;
&lt;P&gt;but I want it like to be resolved automatically each time of invocation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;????&lt;/P&gt;
&lt;P&gt;Define the macro to take a PARAMETER.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then when you CALL the macro pass in the value for the PARAMTER.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(dt);
 .... &amp;amp;DT ....
%mend mymacro;
%mymacro(dt=201901)
%mymacro(dt=201902)
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use a data step to call it multiple times.&lt;/P&gt;
&lt;P&gt;So to call it with the 6 months starting 01JAN2019 you might use a data step like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  basedate='01JAN2019'd;
  do offset=0 to 5 ;
     date=intnx('month',basedate,offset);
     call execute('%nrstr(%mymacro)(dt=' || put(date,yymmn6.) || ')' );
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 16:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-macro-multiple-times/m-p/814326#M321428</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-19T16:25:09Z</dc:date>
    </item>
  </channel>
</rss>

