<?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 for each observation in dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62560#M17787</link>
    <description>Thanks.&lt;BR /&gt;
&lt;BR /&gt;
But if I invoke macro directly with variable name like&lt;BR /&gt;
&lt;BR /&gt;
%MyMacro(optemp1);&lt;BR /&gt;
&lt;BR /&gt;
the macro resolves its argument to optemp1 instead the value in optemp1 &amp;amp; hence fails.</description>
    <pubDate>Fri, 07 Aug 2009 19:19:01 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-08-07T19:19:01Z</dc:date>
    <item>
      <title>Executing macro for each observation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62558#M17785</link>
      <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I have a macro(MyMacro) which I need to execute for a variable in each observation of the dataset.&lt;BR /&gt;
&lt;BR /&gt;
So I have a data set block like below...&lt;BR /&gt;
&lt;BR /&gt;
data files;&lt;BR /&gt;
&lt;BR /&gt;
...&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
call symputx('folderPath',optemp1);&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%MyMacro(&amp;amp;folderPath);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The  Macro seems to be executing for only one observation(I have 4 observations in the files data set). This may be because of the run statement I have after symputx statement. But without that run statement, symputx does not execute and hence folderPath does not get resolved.&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions how to handle this.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Neel</description>
      <pubDate>Fri, 07 Aug 2009 18:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62558#M17785</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-08-07T18:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Executing macro for each observation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62559#M17786</link>
      <description>The run puts the macro outside the datastep.  Just pass the variable name string to the macro.&lt;BR /&gt;
&lt;BR /&gt;
data files;&lt;BR /&gt;
&lt;BR /&gt;
...&lt;BR /&gt;
...&lt;BR /&gt;
%MyMacro(optemp1);&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 07 Aug 2009 19:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62559#M17786</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-08-07T19:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Executing macro for each observation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62560#M17787</link>
      <description>Thanks.&lt;BR /&gt;
&lt;BR /&gt;
But if I invoke macro directly with variable name like&lt;BR /&gt;
&lt;BR /&gt;
%MyMacro(optemp1);&lt;BR /&gt;
&lt;BR /&gt;
the macro resolves its argument to optemp1 instead the value in optemp1 &amp;amp; hence fails.</description>
      <pubDate>Fri, 07 Aug 2009 19:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62560#M17787</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-08-07T19:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Executing macro for each observation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62561#M17788</link>
      <description>You say your program "fails" but it's not been clearly stated as to what fails.&lt;BR /&gt;
&lt;BR /&gt;
It would be best served if you shared the SAS log information where you get the erorr and include expanded SAS code for subscribers / visitors to see -- also explain what the DATA step is attempting to accomplish in your words.&lt;BR /&gt;
&lt;BR /&gt;
And, add to your program for the most expanded info possible (maybe this will also help with self-debugging?):&lt;BR /&gt;
&lt;BR /&gt;
OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN;&lt;BR /&gt;
&lt;BR /&gt;
It is possible to invoke a macro multiple times so that it is expanded / resolved within a DATA step (that is between a DATA statement  and a RUN statement).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 07 Aug 2009 19:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62561#M17788</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-08-07T19:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Executing macro for each observation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62562#M17789</link>
      <description>I have code where I am doing the same thing you are trying to do. Try this and see if it works:&lt;BR /&gt;
&lt;BR /&gt;
data files;&lt;BR /&gt;
set olddataset;&lt;BR /&gt;
....&lt;BR /&gt;
call execute('%MyMacro('||folderPath||');');&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
This way you don't have to create a macro variable and then pass it on to the macro, it will just take the variable in your old data set and pass that on to the macro.&lt;BR /&gt;
&lt;BR /&gt;
Also, instead of creating a new data set called "files", you can just call it "_null_" which won't create a new data set but still run the macro 4 times.&lt;BR /&gt;
&lt;BR /&gt;
Hope it helps!</description>
      <pubDate>Fri, 07 Aug 2009 19:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62562#M17789</guid>
      <dc:creator>kdp</dc:creator>
      <dc:date>2009-08-07T19:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Executing macro for each observation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62563#M17790</link>
      <description>Using call execute statement may cause different bugs&lt;BR /&gt;
use this:&lt;BR /&gt;
&lt;BR /&gt;
/*prepare*/&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
    select '%MyMacro(' || folderPath || ')'  into : mvRun separated by ';'&lt;BR /&gt;
    from lib.dataset;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/*execute*/&lt;BR /&gt;
&amp;amp;mvRun&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Very simple &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; Just remember, macro variable length is limited by 65k symbols</description>
      <pubDate>Fri, 07 Aug 2009 20:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62563#M17790</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-08-07T20:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: Executing macro for each observation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62564#M17791</link>
      <description>Neel&lt;BR /&gt;
 &lt;BR /&gt;
have a look at the function RESOLVE&lt;BR /&gt;
 &lt;BR /&gt;
good luck&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Mon, 10 Aug 2009 08:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Executing-macro-for-each-observation-in-dataset/m-p/62564#M17791</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-08-10T08:36:01Z</dc:date>
    </item>
  </channel>
</rss>

