<?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 Execute a macro in loop with arguments in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/513242#M138278</link>
    <description>Hi ,&lt;BR /&gt;&lt;BR /&gt;Thanks for your prompt response .&lt;BR /&gt;&lt;BR /&gt;Issue got fixed by placing comma between args1 and args2.&lt;BR /&gt;&lt;BR /&gt;call execute(cats('%nrstr(%SasDS(',args1,',',args2,'));'));&lt;BR /&gt;</description>
    <pubDate>Thu, 15 Nov 2018 10:08:10 GMT</pubDate>
    <dc:creator>Lakshmisas</dc:creator>
    <dc:date>2018-11-15T10:08:10Z</dc:date>
    <item>
      <title>How to Execute a macro in loop with arguments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/512827#M138145</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest me in executing a macro for each row in the dataset , passing arguments dynamically as given below.&lt;/P&gt;&lt;P&gt;Suggesting a solution to me is hifhly appreciated.&lt;/P&gt;&lt;P&gt;----------------------------------------------------------------&lt;/P&gt;&lt;P&gt;Read Data1 dataset with Columns "Company" and "DSName"&lt;/P&gt;&lt;P&gt;eg: Company DSName&lt;/P&gt;&lt;P&gt;Comp1 DS1&lt;/P&gt;&lt;P&gt;comp2 DS2&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;-------------------------------------------------------&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set Work.Data1;&lt;BR /&gt;length args1 $300. args2 $100.;&lt;/P&gt;&lt;P&gt;args1 = cats("'C:\Test\",Company,".xlsx'");&lt;BR /&gt;args2 = cats(DSName,'_2018');&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;put "args1=" args1;&lt;BR /&gt;put "args2=" args2;&lt;/P&gt;&lt;P&gt;call execute(cats('%nrstr(%SasDS(',args1,args2,'));'));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------&lt;/P&gt;&lt;P&gt;%let Qtr=Q1;&lt;/P&gt;&lt;P&gt;%macro SasDS(Name,Dss);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;libname Perm&amp;amp;&amp;amp;Qtr 'C:\Test\SasDS\&amp;amp;&amp;amp;Qtr';&lt;/P&gt;&lt;P&gt;PROC IMPORT OUT=Perm&amp;amp;&amp;amp;Qtr.&amp;amp;DSS.&lt;BR /&gt;DATAFILE=&amp;amp;Name.&lt;BR /&gt;DBMS=EXCEL REPLACE;&lt;BR /&gt;SHEET="&amp;amp;&amp;amp;Qtr";&lt;BR /&gt;GETNAMES=YES;&lt;BR /&gt;MIXED=NO;&lt;BR /&gt;SCANTEXT=YES;&lt;BR /&gt;USEDATE=YES;&lt;BR /&gt;SCANTIME=YES;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%mend SasDS;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 03:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/512827#M138145</guid>
      <dc:creator>Lakshmisas</dc:creator>
      <dc:date>2018-11-14T03:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to Execute a macro in loop with arguments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/512828#M138146</link>
      <description>&lt;P&gt;Did it not work? What error did you get?&lt;/P&gt;
&lt;P&gt;Make sure to compile the macro before running the data step that pushes calls to it onto the stack via CALL EXECUTE().&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 03:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/512828#M138146</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-14T03:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to Execute a macro in loop with arguments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/512835#M138149</link>
      <description>&lt;P&gt;The call execute statements will cause the embedded commands to be executed, in sequence, immediately after&amp;nbsp; the data step.&amp;nbsp; Since the code to be executed includes use&amp;nbsp;of the macro SASDS, that macro must be defined prior to the data step execution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps, it's just the way you described your question, but it appears that you don't define the SASDS macro until after the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's not the case, then as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;says, please show us what happened that you didn't expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 04:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/512835#M138149</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-11-14T04:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to Execute a macro in loop with arguments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/512855#M138165</link>
      <description>&lt;P&gt;Your macro expects two arguments separated by a comma, but your call execute does not supply that comma. Expand the call execute:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%SasDS(',args1,',',args2,'));'));
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Nov 2018 07:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/512855#M138165</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-14T07:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Execute a macro in loop with arguments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/513242#M138278</link>
      <description>Hi ,&lt;BR /&gt;&lt;BR /&gt;Thanks for your prompt response .&lt;BR /&gt;&lt;BR /&gt;Issue got fixed by placing comma between args1 and args2.&lt;BR /&gt;&lt;BR /&gt;call execute(cats('%nrstr(%SasDS(',args1,',',args2,'));'));&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Nov 2018 10:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Execute-a-macro-in-loop-with-arguments/m-p/513242#M138278</guid>
      <dc:creator>Lakshmisas</dc:creator>
      <dc:date>2018-11-15T10:08:10Z</dc:date>
    </item>
  </channel>
</rss>

