<?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: executing macro inside a data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/427093#M281340</link>
    <description>&lt;P&gt;So let's eliminate the complexity of your data step from this problem and concentrate on just the CALL EXECUTE issue.&lt;/P&gt;
&lt;P&gt;So first create your dataset and then use a DATA _NULL_ step to generate the macro calls.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro a ;
data FILELIST ;
  ....
  output;
  ....
run;

data _null_;
  set FILELIST;
  call execute(cats('%nrstr(%b)(',id,')'));
run;
%mend a;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can also probably make your data step much simpler (why are you calling CATT() function on string literals?), but perhaps you can leave that for another question.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jan 2018 03:09:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-01-12T03:09:33Z</dc:date>
    <item>
      <title>executing macro inside a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/426765#M281335</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am executing a macro inside a data step and passing the data step variable to the macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But only last record variable is passed all the time (like my loop executed 2 times and 2 times last record variable only passed as a parameter).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output should be&amp;nbsp;&lt;/P&gt;&lt;P&gt;APPDIRECT_PROD_2018011001.dat|20180110|20180110|0000000001|APPDIRECT_PROD_2018011002.|ctl&lt;/P&gt;&lt;P&gt;APPDIRECT_PROD_2018011002.dat|20180110|20180110|0000000002|APPDIRECT_PROD_2018011002.|ctl&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I am getting&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;APPDIRECT_PROD_2018011002.dat|20180110|20180110|0000000002|APPDIRECT_PROD_2018011002.|ctl&lt;/P&gt;&lt;P&gt;APPDIRECT_PROD_2018011002.dat|20180110|20180110|0000000002|APPDIRECT_PROD_2018011002.|ctl&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where exactly the issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Swathi&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 04:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/426765#M281335</guid>
      <dc:creator>sfffdg</dc:creator>
      <dc:date>2018-01-11T04:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: executing macro inside a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/426791#M281336</link>
      <description>&lt;P&gt;You are repeatedly creating macro variable new with call symput.&lt;/P&gt;
&lt;P&gt;You are pushing macro calls onto the execution stack that contain the macro variable name, not it's value.&lt;/P&gt;
&lt;P&gt;Since the macros won't execute before the data step has finished, all macro calls will use the last value put into macro variable new.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of setting macro variables, use data step values in the call execute.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 06:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/426791#M281336</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-11T06:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: executing macro inside a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/426792#M281337</link>
      <description>&lt;P&gt;Thank you Sir,for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I changed the code to &amp;nbsp;the variable directly,instead of the macro variable as i don't want to hardcode the valueas below.&lt;/P&gt;&lt;P&gt;x = cats( '%nrstr(%b(id))' ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then the output is as below.&lt;/P&gt;&lt;P&gt;1 + %b(id)&lt;BR /&gt;id&lt;BR /&gt;2 + %b(id)&lt;BR /&gt;id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;instead of the resolved variable value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any approach to achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 07:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/426792#M281337</guid>
      <dc:creator>sfffdg</dc:creator>
      <dc:date>2018-01-11T07:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: executing macro inside a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/426794#M281338</link>
      <description>&lt;P&gt;Don't hand the &lt;EM&gt;name&lt;/EM&gt; of a data step variable to call execute, but it's &lt;EM&gt;values&lt;/EM&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x = cats('%nrstr(%b('!!trim(id)!!'))');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jan 2018 07:54:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/426794#M281338</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-11T07:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: executing macro inside a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/427002#M281339</link>
      <description>&lt;P&gt;Thank you sir!!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 20:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/427002#M281339</guid>
      <dc:creator>sfffdg</dc:creator>
      <dc:date>2018-01-11T20:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: executing macro inside a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/427093#M281340</link>
      <description>&lt;P&gt;So let's eliminate the complexity of your data step from this problem and concentrate on just the CALL EXECUTE issue.&lt;/P&gt;
&lt;P&gt;So first create your dataset and then use a DATA _NULL_ step to generate the macro calls.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro a ;
data FILELIST ;
  ....
  output;
  ....
run;

data _null_;
  set FILELIST;
  call execute(cats('%nrstr(%b)(',id,')'));
run;
%mend a;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can also probably make your data step much simpler (why are you calling CATT() function on string literals?), but perhaps you can leave that for another question.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 03:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/executing-macro-inside-a-data-step/m-p/427093#M281340</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-01-12T03:09:33Z</dc:date>
    </item>
  </channel>
</rss>

