<?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: Calling a macro program 30 times in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Calling-a-macro-program-30-times/m-p/6547#M647</link>
    <description>Hi Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your detailed response.  I prefer the first method although it uses 2 macros.  It is more readable and I don't want to modify my original macro &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
I found the following idea in some pdf files from sugi, that's same as your first idea.  &lt;BR /&gt;
&lt;BR /&gt;
%macro create(howmany);&lt;BR /&gt;
%do i=1 %to &amp;amp;howmany;&lt;BR /&gt;
%task(&amp;amp;i);&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend create;&lt;BR /&gt;
&lt;BR /&gt;
%create(3)&lt;BR /&gt;
&lt;BR /&gt;
Thanks.&lt;BR /&gt;
&lt;BR /&gt;
-Nilan</description>
    <pubDate>Sat, 26 Jan 2008 15:52:09 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-01-26T15:52:09Z</dc:date>
    <item>
      <title>Calling a macro program 30 times</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Calling-a-macro-program-30-times/m-p/6545#M645</link>
      <description>I created a macro program.  I'd call it by&lt;BR /&gt;
%task(day_num);&lt;BR /&gt;
&lt;BR /&gt;
If I want to call it 30 times with different day_num, how would I set it in a loop (Is it the efficient way)?   My day_num goes from 1 to 30 in sequence.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.&lt;BR /&gt;
&lt;BR /&gt;
-Nilan</description>
      <pubDate>Fri, 25 Jan 2008 22:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Calling-a-macro-program-30-times/m-p/6545#M645</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-25T22:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro program 30 times</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Calling-a-macro-program-30-times/m-p/6546#M646</link>
      <description>Hi:&lt;BR /&gt;
  Again, a macro program with a macro %DO loop is going to help you out. There are 2 different ways to write your macro program.&lt;BR /&gt;
[pre]&lt;BR /&gt;
** Approach 1: use 2 macro programs;&lt;BR /&gt;
** the macro program for your main task;&lt;BR /&gt;
%macro task(day=1);&lt;BR /&gt;
  proc print data=sashelp.shoes(obs=&amp;amp;day);&lt;BR /&gt;
    title "TASK macro: value of DAY is &amp;amp;day";&lt;BR /&gt;
  run;&lt;BR /&gt;
%mend task;&lt;BR /&gt;
       &lt;BR /&gt;
** then make a macro program that will just;&lt;BR /&gt;
** invoke the %TASK macro inside a %do loop;&lt;BR /&gt;
%macro dotask(start=, stop=);&lt;BR /&gt;
  %do i = &amp;amp;start %to &amp;amp;stop;&lt;BR /&gt;
     %task(day=&amp;amp;i);&lt;BR /&gt;
  %end;&lt;BR /&gt;
%mend dotask;&lt;BR /&gt;
        &lt;BR /&gt;
%dotask(start=1,stop=4);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Which is not really 1 macro program, but is 2 -- the first one that does something(in this case, a PROC PRINT). And the second macro program that uses a %DO loop to invoke the first macro program. There is an alternate way to code this, which is to just use one macro program:&lt;BR /&gt;
[pre]&lt;BR /&gt;
** Approach 2: do everything within 1 macro program;&lt;BR /&gt;
** and put the program code you want to generate;&lt;BR /&gt;
** inside the %DO loop;&lt;BR /&gt;
%macro alttask(start=, stop=);&lt;BR /&gt;
  %do i = &amp;amp;start %to &amp;amp;stop;&lt;BR /&gt;
    proc print data=sashelp.shoes(obs=&amp;amp;i);&lt;BR /&gt;
      title "ALTTASK macro: value of I is &amp;amp;i";&lt;BR /&gt;
    run;&lt;BR /&gt;
  %end;&lt;BR /&gt;
%mend alttask;&lt;BR /&gt;
        &lt;BR /&gt;
%alttask(start=3,stop=6);&lt;BR /&gt;
    &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
I prefer the use of keyword parameters for macro programs instead of positional parameters. The thing I like about keyword parameters is that you can specify default values to use if the parameter is not specified and I just find macros with keyword parameters easier to maintain and easier to invoke. But that's my preference (based on mumblety-mumble years of coding in SAS) -- you could, of course, code your macros with positional parameters. However, my examples always come with keyword parameters.&lt;BR /&gt;
 &lt;BR /&gt;
For more help with writing or invoking macro programs, consult the SAS Macro facility documentation or contact Tech Support for help with a specific coding problem.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Sat, 26 Jan 2008 04:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Calling-a-macro-program-30-times/m-p/6546#M646</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-01-26T04:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro program 30 times</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Calling-a-macro-program-30-times/m-p/6547#M647</link>
      <description>Hi Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your detailed response.  I prefer the first method although it uses 2 macros.  It is more readable and I don't want to modify my original macro &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
I found the following idea in some pdf files from sugi, that's same as your first idea.  &lt;BR /&gt;
&lt;BR /&gt;
%macro create(howmany);&lt;BR /&gt;
%do i=1 %to &amp;amp;howmany;&lt;BR /&gt;
%task(&amp;amp;i);&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend create;&lt;BR /&gt;
&lt;BR /&gt;
%create(3)&lt;BR /&gt;
&lt;BR /&gt;
Thanks.&lt;BR /&gt;
&lt;BR /&gt;
-Nilan</description>
      <pubDate>Sat, 26 Jan 2008 15:52:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Calling-a-macro-program-30-times/m-p/6547#M647</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-26T15:52:09Z</dc:date>
    </item>
  </channel>
</rss>

