<?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: Call Execute not conditionally executing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Call-Execute-not-conditionally-executing/m-p/30884#M5913</link>
    <description>Hi Cameron.&lt;BR /&gt;
This is a timing issue : the CALL EXECUTE statement just &lt;I&gt;stores&lt;/I&gt; code in memory, and executes the whole bunch of stored code &lt;I&gt;after the end&lt;/I&gt; of the Data step.&lt;BR /&gt;
What you would like here is your macro-program to execute &lt;I&gt;within&lt;/I&gt; the Data step. It will not. In fact, even if you changed the code to have %GetCode execute for each observation, it would not write anything correct in the output data set, because your macro is SQL, and it cannot be run within the Data step. Remember that macro is just copy &amp;amp; paste ! So if you run %getCode, that means that you execute the proc Sql ... statements just at the time the %getCode statement is read.&lt;BR /&gt;
&lt;BR /&gt;
I think you could come to an answer without macro coding. Something like that (not tested) :&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA work.testCallExecute (KEEP=start_pos code_block) ;&lt;BR /&gt;
  SET work.progparse2 ;&lt;BR /&gt;
  BY start_pos ; /* keep track of changing values for start_pos (dataset must be sorted beforehand */&lt;BR /&gt;
  RETAIN code_block ; /* store values in memory from an observation to the following */&lt;BR /&gt;
  LENGTH code_block $ 500 ;&lt;BR /&gt;
  FORMAT code_block $500.;&lt;BR /&gt;
  IF FIRST.start_pos THEN code_block="" ; /* initialize */&lt;BR /&gt;
  code_block=COMPBL(code_block!!" "!!progText!!";") ; /* build up values */&lt;BR /&gt;
  IF LAST.code_block THEN OUTPUT ; /* write when done */&lt;BR /&gt;
RUN ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Regards,&lt;BR /&gt;
Olivier</description>
    <pubDate>Mon, 14 Jul 2008 07:42:37 GMT</pubDate>
    <dc:creator>Olivier</dc:creator>
    <dc:date>2008-07-14T07:42:37Z</dc:date>
    <item>
      <title>Call Execute not conditionally executing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-Execute-not-conditionally-executing/m-p/30883#M5912</link>
      <description>Hi All,&lt;BR /&gt;
I have some code where I parse a .sas file into a data set. I then&lt;BR /&gt;
apply some recoding rules to flag whether it is the start of a&lt;BR /&gt;
statement, the input dataset, the output dataset etc.  I am using this&lt;BR /&gt;
as a basis to develop a code documentation tool.&lt;BR /&gt;
&lt;BR /&gt;
What I want to do is to combine the rows of code that I parse into&lt;BR /&gt;
rows back into a field based on the code block (ie: I want line 1&lt;BR /&gt;
which has 'Proc printto log=mylog new;' and line 2 'run;' to become&lt;BR /&gt;
field 1 in a new table.&lt;BR /&gt;
&lt;BR /&gt;
I wrote the following code to do this. combining is based on a col&lt;BR /&gt;
called start_pos which is a number relating to the data step/proc&lt;BR /&gt;
statement;&lt;BR /&gt;
&lt;BR /&gt;
%macro getcode(n);&lt;BR /&gt;
       proc sql noprint;&lt;BR /&gt;
               select&lt;BR /&gt;
                       progtext&lt;BR /&gt;
               into:&lt;BR /&gt;
                       strVar separated by ';'&lt;BR /&gt;
               from&lt;BR /&gt;
                       progparse2&lt;BR /&gt;
               where&lt;BR /&gt;
                       start_pos =&amp;amp;n;&lt;BR /&gt;
       run;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
data testCallExecute;&lt;BR /&gt;
       set progparse2(keep=start_pos code_block);&lt;BR /&gt;
               format code_block $500.;&lt;BR /&gt;
               call execute("%getcode("||start_pos||");");&lt;BR /&gt;
               code_block="&amp;amp;strVar";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I have tried the above code either referencing progparse2 via set and&lt;BR /&gt;
also an array looping through each line.  What I get in the output&lt;BR /&gt;
dataset is the first combined data step for each step.  ie: the call&lt;BR /&gt;
execute statement does not execute the %getcode macro based on the set&lt;BR /&gt;
dataset value of start_pos. It will always return the first combined&lt;BR /&gt;
value.&lt;BR /&gt;
&lt;BR /&gt;
This has me stumped.  Any help is appreciated and if this does not&lt;BR /&gt;
make sense just let me know.</description>
      <pubDate>Fri, 11 Jul 2008 23:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-Execute-not-conditionally-executing/m-p/30883#M5912</guid>
      <dc:creator>CameronLawson</dc:creator>
      <dc:date>2008-07-11T23:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Call Execute not conditionally executing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-Execute-not-conditionally-executing/m-p/30884#M5913</link>
      <description>Hi Cameron.&lt;BR /&gt;
This is a timing issue : the CALL EXECUTE statement just &lt;I&gt;stores&lt;/I&gt; code in memory, and executes the whole bunch of stored code &lt;I&gt;after the end&lt;/I&gt; of the Data step.&lt;BR /&gt;
What you would like here is your macro-program to execute &lt;I&gt;within&lt;/I&gt; the Data step. It will not. In fact, even if you changed the code to have %GetCode execute for each observation, it would not write anything correct in the output data set, because your macro is SQL, and it cannot be run within the Data step. Remember that macro is just copy &amp;amp; paste ! So if you run %getCode, that means that you execute the proc Sql ... statements just at the time the %getCode statement is read.&lt;BR /&gt;
&lt;BR /&gt;
I think you could come to an answer without macro coding. Something like that (not tested) :&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA work.testCallExecute (KEEP=start_pos code_block) ;&lt;BR /&gt;
  SET work.progparse2 ;&lt;BR /&gt;
  BY start_pos ; /* keep track of changing values for start_pos (dataset must be sorted beforehand */&lt;BR /&gt;
  RETAIN code_block ; /* store values in memory from an observation to the following */&lt;BR /&gt;
  LENGTH code_block $ 500 ;&lt;BR /&gt;
  FORMAT code_block $500.;&lt;BR /&gt;
  IF FIRST.start_pos THEN code_block="" ; /* initialize */&lt;BR /&gt;
  code_block=COMPBL(code_block!!" "!!progText!!";") ; /* build up values */&lt;BR /&gt;
  IF LAST.code_block THEN OUTPUT ; /* write when done */&lt;BR /&gt;
RUN ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Regards,&lt;BR /&gt;
Olivier</description>
      <pubDate>Mon, 14 Jul 2008 07:42:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-Execute-not-conditionally-executing/m-p/30884#M5913</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2008-07-14T07:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Call Execute not conditionally executing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-Execute-not-conditionally-executing/m-p/30885#M5914</link>
      <description>Oliver,&lt;BR /&gt;
You would be correct.  Many thanks.  Ironically I always forget about retain!.  Many thanks.  This is far more efficient also.</description>
      <pubDate>Tue, 15 Jul 2008 04:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-Execute-not-conditionally-executing/m-p/30885#M5914</guid>
      <dc:creator>CameronLawson</dc:creator>
      <dc:date>2008-07-15T04:49:37Z</dc:date>
    </item>
  </channel>
</rss>

