<?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: How to invoke a macro inside a do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568664#M160130</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro download(daty);
proc sql;
create table asp as select a.name,a.income,
             b.name as name1,b.income as income1,
             c.name as name2,c.income as income2,
             a.dat from
        precalltesttab_61 a,
        precalltesttab_62 b,
        precalltesttab_63 c
        where a.dat=b.dat
        and b.dat=c.dat
        and a.dat=c.dat
        and a.dat=&amp;amp;daty.
        ;
        quit;
%mend download;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You overwrite dataset asp with every macro call, so only the result of the last call will "survive".&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jun 2019 09:08:31 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-06-25T09:08:31Z</dc:date>
    <item>
      <title>How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568629#M160099</link>
      <description>Iam in process of automating SAS code,I have a macro whose input argument is date.&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;%monthly("20jun2019"d)&lt;BR /&gt;%monthly("21jun2019"d)&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;%monthly("29jun2019"d)&lt;BR /&gt;&lt;BR /&gt;I need to automate the above code.i have tried using do loop but it didn't worked.here is the code that I have tried.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Data d;&lt;BR /&gt;Do i="20jun2019"d to "29jun2019"d;&lt;BR /&gt;Output&lt;BR /&gt;Call execute ("%monthly",i);&lt;BR /&gt;End;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Kindly let me know how to invoke macro inside do loop or is there any other process to automate the above process.</description>
      <pubDate>Tue, 25 Jun 2019 05:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568629#M160099</guid>
      <dc:creator>sravanece11</dc:creator>
      <dc:date>2019-06-25T05:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568632#M160102</link>
      <description>&lt;P&gt;I am not aware of the exact error you are getting and also I am not aware of the macro code but I think you are not passing i as a parameter to monthly macro. The monthly macro is expecting a parameter perhaps.&lt;/P&gt;&lt;P&gt;Did you try CALL EXECUTE ('%monhtly(i)') instead of what you have written?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 05:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568632#M160102</guid>
      <dc:creator>koyelghosh</dc:creator>
      <dc:date>2019-06-25T05:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568634#M160104</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/207572"&gt;@sravanece11&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Iam in process of automating SAS code,I have a macro whose input argument is date.&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;%monthly("20jun2019"d)&lt;BR /&gt;%monthly("21jun2019"d)&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;%monthly("29jun2019"d)&lt;BR /&gt;&lt;BR /&gt;I need to automate the above code.i have tried using do loop but it didn't worked.here is the code that I have tried.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Data d;&lt;BR /&gt;Do i="20jun2019"d to "29jun2019"d;&lt;BR /&gt;Output&lt;BR /&gt;Call execute ("%monthly",i);&lt;BR /&gt;End;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Kindly let me know how to invoke macro inside do loop or is there any other process to automate the above process.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to pass a valid macro-call to call execute, also note that the behaviour of call execute depends on the quotes you use, see docs for details.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should work as expected:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%monthly(', i, ');'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 05:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568634#M160104</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-06-25T05:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568635#M160105</link>
      <description>&lt;P&gt;And if you have macro code inside %monthly, you need to further delay the macro resolution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%monthly(', i, '));'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is always a good idea to use %nrstr when calling macros with call execute.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 06:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568635#M160105</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-25T06:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568657#M160123</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;After running the code that you suggested,iam getting output of only the&lt;BR /&gt;last date ie 27jun2019.&lt;BR /&gt;&lt;BR /&gt;I need output for all the dates provided in the do loop&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jun 2019 08:47:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568657#M160123</guid>
      <dc:creator>sravanece11</dc:creator>
      <dc:date>2019-06-25T08:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568658#M160124</link>
      <description>&lt;P&gt;Please show the code of your macro.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 08:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568658#M160124</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-25T08:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568660#M160126</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have given sample data,macro&amp;nbsp; code in the attachement,kindly have a look.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 09:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568660#M160126</guid>
      <dc:creator>sravanece11</dc:creator>
      <dc:date>2019-06-25T09:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568664#M160130</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro download(daty);
proc sql;
create table asp as select a.name,a.income,
             b.name as name1,b.income as income1,
             c.name as name2,c.income as income2,
             a.dat from
        precalltesttab_61 a,
        precalltesttab_62 b,
        precalltesttab_63 c
        where a.dat=b.dat
        and b.dat=c.dat
        and a.dat=c.dat
        and a.dat=&amp;amp;daty.
        ;
        quit;
%mend download;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You overwrite dataset asp with every macro call, so only the result of the last call will "survive".&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 09:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568664#M160130</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-25T09:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568665#M160131</link>
      <description>&lt;P&gt;so what changes should i make in the code such that i should be able to retrive data for all the macros invoked in do loop.( i mean for all the dates provided in do loop)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 09:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568665#M160131</guid>
      <dc:creator>sravanece11</dc:creator>
      <dc:date>2019-06-25T09:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568668#M160133</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/207572"&gt;@sravanece11&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;so what changes should i make in the code such that i should be able to retrive data for all the macros invoked in do loop.( i mean for all the dates provided in do loop)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Depends on what you need: one dataset for each date (not recommended, because further processing will require more loops) or one dataset with the data of all dates you currently pass a parameter?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 09:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568668#M160133</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-06-25T09:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568669#M160134</link>
      <description>&lt;P&gt;Add a timestamp to the dataset name:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro download(daty);
%local datestring;
%let datestring=%sysfunc(putn(&amp;amp;daty.,yymmddn8.));
proc sql;
create table asp&amp;amp;datestring. as select a.name,a.income,
             b.name as name1,b.income as income1,
             c.name as name2,c.income as income2,
             a.dat from
        precalltesttab_61 a,
        precalltesttab_62 b,
        precalltesttab_63 c
        where a.dat=b.dat
        and b.dat=c.dat
        and a.dat=c.dat
        and a.dat=&amp;amp;daty.
        ;
        quit;
%mend download;

data _null_;
do i = '20jun2019'd to '27jun2019'd;
  call execute('%nrstr(%download('!!put(i,best.)!!'));');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;already mentioned, this is usually not a good idea.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 09:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568669#M160134</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-25T09:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568683#M160143</link>
      <description>one dataset with the data of all dates i currently pass as a parameter&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jun 2019 10:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568683#M160143</guid>
      <dc:creator>sravanece11</dc:creator>
      <dc:date>2019-06-25T10:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568708#M160147</link>
      <description>&lt;P&gt;Untested code, you don't need a loop any more, just pass first and last date to the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro download(fromDate, untilDate);
proc sql;
create table asp as select a.name,a.income,
             b.name as name1,b.income as income1,
             c.name as name2,c.income as income2,
             a.dat from
        precalltesttab_61 a,
        precalltesttab_62 b,
        precalltesttab_63 c
        where a.dat=b.dat
        and b.dat=c.dat
        and a.dat=c.dat
        and (&amp;amp;fromDate. &amp;lt;= a.dat &amp;lt;= &amp;amp;untilDate.)
        ;
        quit;
%mend download;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jun 2019 11:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568708#M160147</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-06-25T11:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568714#M160150</link>
      <description>&lt;P&gt;Create intermediate datasets and append:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro download(daty);

proc sql;
create table int as
select
  a.name,
  a.income,
  b.name as name1,
  b.income as income1,
  c.name as name2,
  c.income as income2,
  a.dat
from
  precalltesttab_61 a,
  precalltesttab_62 b,
  precalltesttab_63 c
where
  a.dat=b.dat
  and b.dat=c.dat
  and a.dat=&amp;amp;daty.
;
quit;

proc append data=int base=asp force;
run;

%mend download;

%if %sysfunc(exist(asp)) %then %do;
proc delete data=asp;
run;
%end;

data _null_;
do i = '20jun2019'd to '27jun2019'd;
  call execute('%nrstr(%download('!!put(i,best.)!!'));');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jun 2019 12:01:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568714#M160150</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-25T12:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to invoke a macro inside a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568719#M160154</link>
      <description>Thanks a lot,it's working.&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jun 2019 12:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-invoke-a-macro-inside-a-do-loop/m-p/568719#M160154</guid>
      <dc:creator>sravanece11</dc:creator>
      <dc:date>2019-06-25T12:18:59Z</dc:date>
    </item>
  </channel>
</rss>

