<?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: problem call execute in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9387#M492</link>
    <description>At what stage do you expect the macro invoked by the call execute() to:&lt;BR /&gt;
1 compile&lt;BR /&gt;
2 resolve&lt;BR /&gt;
??</description>
    <pubDate>Thu, 30 Sep 2010 07:04:26 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2010-09-30T07:04:26Z</dc:date>
    <item>
      <title>problem call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9385#M490</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have a problem with call execute that I don’t understand. Basically, what I am doing is merging 2 datasets (old and new versions) and then, if a variable has been updated, I write the information in an audit table. Below is a simplified version of my code.&lt;BR /&gt;
&lt;BR /&gt;
In my dataset test, I have only one row with var1_old="oldval" and var1_new="new&lt;B&gt;.&lt;/B&gt;"&lt;BR /&gt;
The macro createdataaudit should output one record in the dataset audit. However, the row is not added to the table.&lt;BR /&gt;
I found the reason but I don’t understand it. If I remove the "dot” from the variable var1_new, the macro is executed and one row is added to the dataset. It doesn’t work with the ‘dot’ at the end of the variable var1_new. &lt;BR /&gt;
Also if I had some text after the “dot”, the macro executes and writes a row in audit table.&lt;BR /&gt;
&lt;BR /&gt;
If someone could explain to me, I would really appreciate. Thanks a lot!!!!&lt;BR /&gt;
&lt;BR /&gt;
%macro createdataaudit(outdata,newval,oldval);&lt;BR /&gt;
&lt;BR /&gt;
%if &amp;amp;newval ne &amp;amp;oldval %then %do;&lt;BR /&gt;
	%if %sysfunc(exist(&amp;amp;outdata)) %then %do ;&lt;BR /&gt;
		PROC SQL;&lt;BR /&gt;
		INSERT INTO &amp;amp;outdata&lt;BR /&gt;
		SET          newval=&amp;amp;newval,oldval=&amp;amp;oldval		;&lt;BR /&gt;
		QUIT;&lt;BR /&gt;
	%end;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%mend createdataaudit;&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
	set test;&lt;BR /&gt;
	if  strip(var1_old) ne strip(var1_new)  then do;&lt;BR /&gt;
	call execute('%createdataaudit(audit,'||quote(strip(var1_old))||','||quote(strip(var1_new))||');');&lt;BR /&gt;
	end;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 29 Sep 2010 22:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9385#M490</guid>
      <dc:creator>mrom34</dc:creator>
      <dc:date>2010-09-29T22:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: problem call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9386#M491</link>
      <description>Mrom,&lt;BR /&gt;
&lt;BR /&gt;
Quite possibly I'm not following everything that you're doing, but WHY would you expect the variable TO work with a period after it?&lt;BR /&gt;
&lt;BR /&gt;
A period would only be relevant after a variable name if you were referring to a macro variable.&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Thu, 30 Sep 2010 00:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9386#M491</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-09-30T00:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: problem call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9387#M492</link>
      <description>At what stage do you expect the macro invoked by the call execute() to:&lt;BR /&gt;
1 compile&lt;BR /&gt;
2 resolve&lt;BR /&gt;
??</description>
      <pubDate>Thu, 30 Sep 2010 07:04:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9387#M492</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-09-30T07:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: problem call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9388#M493</link>
      <description>If you take a longer look at the original posting you will see that “new.”  is not the name of a variable, just plain text.  After I tried to run this program, I got a little confused myself.&lt;BR /&gt;
&lt;BR /&gt;
First of all, I don’t think that call execute has anything to do with the problem.  The record is not appended to the audit dataset if you invoke the macro like %createdataaudit(audit,"old val","new."), which is the text generated by the call execute statement.  See the log below:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
1159  data audit;&lt;BR /&gt;
1160  length newval oldval $ 8;&lt;BR /&gt;
1161  run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Variable newval is uninitialized.&lt;BR /&gt;
NOTE: Variable oldval is uninitialized.&lt;BR /&gt;
NOTE: The data set WORK.AUDIT has 1 observations and 2 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.03 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
1162&lt;BR /&gt;
1163  %macro createdataaudit(outdata,newval,oldval);&lt;BR /&gt;
1164&lt;BR /&gt;
1165  %if &amp;amp;newval ne &amp;amp;oldval %then %do;&lt;BR /&gt;
1166  %if %sysfunc(exist(&amp;amp;outdata)) %then %do ;&lt;BR /&gt;
1167  PROC SQL;&lt;BR /&gt;
1168  INSERT INTO &amp;amp;outdata&lt;BR /&gt;
1169  SET newval=&amp;amp;newval, oldval=&amp;amp;oldval;&lt;BR /&gt;
1170  QUIT;&lt;BR /&gt;
1171  %end;&lt;BR /&gt;
1172  %end;&lt;BR /&gt;
1173&lt;BR /&gt;
1174  %mend createdataaudit;&lt;BR /&gt;
1175&lt;BR /&gt;
1176  options mprint mlogic;&lt;BR /&gt;
1177  %createdataaudit(audit,"old val","new.")&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Beginning execution.&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter OUTDATA has value audit&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter NEWVAL has value "old val"&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter OLDVAL has value "new."&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  %IF condition &amp;amp;newval ne &amp;amp;oldval is TRUE&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  %IF condition %sysfunc(exist(&amp;amp;outdata)) is TRUE&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Ending execution.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Here is where I’m getting confused, if the log says that the condition  sysfunc(exist(&amp;amp;outdata)) is true, then why is the SQL statement not written to the input stack?  If you now invoke the macro without the period, here is the result:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
1178  %createdataaudit(audit,"old val","new")&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Beginning execution.&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter OUTDATA has value audit&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter NEWVAL has value "old val"&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter OLDVAL has value "new"&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  %IF condition &amp;amp;newval ne &amp;amp;oldval is TRUE&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  %IF condition %sysfunc(exist(&amp;amp;outdata)) is TRUE&lt;BR /&gt;
MPRINT(CREATEDATAAUDIT):   PROC SQL;&lt;BR /&gt;
MPRINT(CREATEDATAAUDIT):   INSERT INTO audit SET newval="old val", oldval="new";&lt;BR /&gt;
NOTE: 1 row was inserted into WORK.AUDIT.&lt;BR /&gt;
&lt;BR /&gt;
MPRINT(CREATEDATAAUDIT):   QUIT;&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Ending execution.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Now, the SQL statement is correctly written to the input stack.  The problem must have something to do with the way that the macro processor interprets the period.&lt;BR /&gt;
&lt;BR /&gt;
Just to make things more confusing, I said earlier that I didn’t think call execute had anything to do with the problem.  However, take a look at the log when you do invoke the macro with call execute:&lt;BR /&gt;
&lt;BR /&gt;
[pre] &lt;BR /&gt;
1179  data test;&lt;BR /&gt;
1180      var1_old = 'old val';&lt;BR /&gt;
1181      var1_new = 'new.';&lt;BR /&gt;
1182  run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The data set WORK.TEST has 1 observations and 2 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
1183&lt;BR /&gt;
1184  data test;&lt;BR /&gt;
1185  set test;&lt;BR /&gt;
1186  if strip(var1_old) ne strip(var1_new) then do;&lt;BR /&gt;
1187  call&lt;BR /&gt;
1187! execute('%createdataaudit(audit,'||quote(strip(var1_old))||','||quote(strip(var1_new))||');&lt;BR /&gt;
1187! ');&lt;BR /&gt;
1188  end;&lt;BR /&gt;
1189  run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.03 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Beginning execution.&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter OUTDATA has value audit&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter NEWVAL has value "old val"&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter OLDVAL has value "new."&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  %IF condition &amp;amp;newval ne &amp;amp;oldval is TRUE&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  %IF condition %sysfunc(exist(&amp;amp;outdata)) is TRUE&lt;BR /&gt;
MPRINT(CREATEDATAAUDIT):   PROC SQL;&lt;BR /&gt;
MPRINT(CREATEDATAAUDIT):   INSERT INTO audit SET newval="old val", oldval="new.";&lt;BR /&gt;
MPRINT(CREATEDATAAUDIT):   QUIT;&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Ending execution.&lt;BR /&gt;
NOTE: There were 1 observations read from the data set WORK.TEST.&lt;BR /&gt;
NOTE: The data set WORK.TEST has 1 observations and 2 variables.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: CALL EXECUTE generated line.&lt;BR /&gt;
1    + PROC SQL; INSERT INTO audit SET newval="old val", oldval="new."; QUIT;;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Note that now, the SQL statement is displayed on the mprint lines and the log says that call execute did generate the SQL statement.  However, it’s obvious that the statement was never executed.  If the statement were executed, there would have been a note in the log pertaining to process time used by the SQL procedure.&lt;BR /&gt;
&lt;BR /&gt;
Not that it helps explain why the previous code did not work, but by making some simple modifications to the macro and the way that it’s called, you can create a macro that will successfully append the record to the dataset:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
1190  %macro createdataaudit(outdata,newval,oldval);&lt;BR /&gt;
1191&lt;BR /&gt;
1192  %if &amp;amp;newval ne &amp;amp;oldval %then %do;&lt;BR /&gt;
1193  %if %sysfunc(exist(&amp;amp;outdata)) %then %do ;&lt;BR /&gt;
1194  PROC SQL;&lt;BR /&gt;
1195  INSERT INTO &amp;amp;outdata&lt;BR /&gt;
1196  SET newval="%bquote(&amp;amp;newval)", oldval="%bquote(&amp;amp;oldval)";&lt;BR /&gt;
1197  QUIT;&lt;BR /&gt;
1198  %end;&lt;BR /&gt;
1199  %end;&lt;BR /&gt;
1200&lt;BR /&gt;
1201  %mend createdataaudit;&lt;BR /&gt;
1202&lt;BR /&gt;
1203  data test;&lt;BR /&gt;
1204  set test;&lt;BR /&gt;
1205  if strip(var1_old) ne strip(var1_new) then do;&lt;BR /&gt;
1206  call execute('%createdataaudit(audit,'||strip(var1_old)||','||strip(var1_new)||');');&lt;BR /&gt;
1207  end;&lt;BR /&gt;
1208  run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Beginning execution.&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter OUTDATA has value audit&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter NEWVAL has value old val&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Parameter OLDVAL has value new.&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  %IF condition &amp;amp;newval ne &amp;amp;oldval is TRUE&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  %IF condition %sysfunc(exist(&amp;amp;outdata)) is TRUE&lt;BR /&gt;
MPRINT(CREATEDATAAUDIT):   PROC SQL;&lt;BR /&gt;
MPRINT(CREATEDATAAUDIT):   INSERT INTO audit SET newval="old val", oldval="new.";&lt;BR /&gt;
MPRINT(CREATEDATAAUDIT):   QUIT;&lt;BR /&gt;
MLOGIC(CREATEDATAAUDIT):  Ending execution.&lt;BR /&gt;
NOTE: There were 1 observations read from the data set WORK.TEST.&lt;BR /&gt;
NOTE: The data set WORK.TEST has 1 observations and 2 variables.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: CALL EXECUTE generated line.&lt;BR /&gt;
1    + PROC SQL;&lt;BR /&gt;
1    +           INSERT INTO audit SET newval="old val", oldval="new.";&lt;BR /&gt;
NOTE: 1 row was inserted into WORK.AUDIT.&lt;BR /&gt;
&lt;BR /&gt;
1    +                                                                  QUIT;&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Even though the above macro does work, I would really like to understand exactly why the original macro failed.</description>
      <pubDate>Thu, 30 Sep 2010 15:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9388#M493</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2010-09-30T15:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: problem call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9389#M494</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot for your answer. You macro works very well. &lt;BR /&gt;
&lt;BR /&gt;
I found another solution. In the macro createaudit, if I replace &lt;I&gt;%if &amp;amp;newval ne &amp;amp;oldval %then %do;&lt;/I&gt; by &lt;I&gt;if &lt;B&gt;%str&lt;/B&gt;(&amp;amp;newval) ne &lt;B&gt;%str&lt;/B&gt;(&amp;amp;oldval) %then %do;&lt;/I&gt;, then the macro appends the record to the dataset.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I am still confused about this program and I would really like to understand why it is not working.&lt;BR /&gt;
&lt;BR /&gt;
Romain</description>
      <pubDate>Thu, 30 Sep 2010 16:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-call-execute/m-p/9389#M494</guid>
      <dc:creator>mrom34</dc:creator>
      <dc:date>2010-09-30T16:40:46Z</dc:date>
    </item>
  </channel>
</rss>

