<?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: PROC COMPARE in call execute in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-in-call-execute-in-data-step/m-p/605732#M175808</link>
    <description>Thank you greatly</description>
    <pubDate>Wed, 20 Nov 2019 13:43:10 GMT</pubDate>
    <dc:creator>i_Van</dc:creator>
    <dc:date>2019-11-20T13:43:10Z</dc:date>
    <item>
      <title>PROC COMPARE in call execute in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-in-call-execute-in-data-step/m-p/605716#M175801</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to compare 2 tables inside the macros and then run this macro with a set of parameters, but calling PROC COMPARE in different ways (direct call on two tables, calling macro via %MACRO_NAME, and calling macro from data step via call execute) gives different results&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
input a $ b;
datalines;
a 1
b 2
c 3
run;

data t2;
input a $ b;
datalines;
a 1
b 2
c 3
d 4
run;

proc compare base=t1
     compare=t2 noprint;
run;
%put WARNING: direct compare &amp;amp;=sysinfo;

%macro compar(table1, table2, comment='');
	proc compare base=&amp;amp;table1
	     compare=&amp;amp;table2 noprint;
	run;
	%put WARNING: &amp;amp;comment &amp;amp;=sysinfo;
%mend;

%compar(t1,t2,comment=direct macro invoke);

data compare_table;
input a $ b $;
datalines;
t1 t2
run;

data null;
set compare_table;
call execute('%compar(' || a||','||b||',comment=macro invoke from data step)');&lt;BR /&gt;call execute('%compar(t1,t2,comment=macro invoke from data step full copy)');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The direct call on two tables, calling macro via %MACRO_NAME obviously shows that tables are different&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BUT calling macro from data step via call execute shows that tables are equal, even CALL EXECUTE('%MACRO') shows the wrong result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some remarks if any way around exists:&lt;/P&gt;&lt;P&gt;I have to compare 2 tables in macro to be able to use %if %then to choose&amp;nbsp; the behavior of the program depending on the equity of tables&lt;/P&gt;&lt;P&gt;I have to call macros several times with the parameters storing in the table&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 13:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-in-call-execute-in-data-step/m-p/605716#M175801</guid>
      <dc:creator>i_Van</dc:creator>
      <dc:date>2019-11-20T13:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: PROC COMPARE in call execute in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-in-call-execute-in-data-step/m-p/605721#M175803</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you have to use nrstr :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('%nrstr(%compar)(' || a||','||b||',comment=macro invoke from data step)');call execute('%compar(t1,t2,comment=macro invoke from data step full copy)');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in order to avoid an early macro resolution. In your example, the macrovariable sysinfo is resolved before the execution of proc compare.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 13:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-in-call-execute-in-data-step/m-p/605721#M175803</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-11-20T13:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: PROC COMPARE in call execute in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-in-call-execute-in-data-step/m-p/605725#M175805</link>
      <description>&lt;P&gt;This is a clasic CALL EXECUTE timing problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When CALL EXECUTE executes a macro, it resolves all of the macro variable references and executes macro language statements immediately.&amp;nbsp; It resolves them BEFORE any of the SAS code has actually executed.&amp;nbsp; If you check your log, the %PUT statements show up before the PROC COMPARE step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;60   data null;
61   set compare_table;
62   call execute('%compar(' || a||','||b||',comment=macro invoke from data step)');
63   call execute('%compar(t1,t2,comment=macro invoke from data step full copy)');
64   run;

WARNING: macro invoke from data step SYSINFO=0
WARNING: macro invoke from data step full copy SYSINFO=0
NOTE: There were 1 observations read from the data set WORK.COMPARE_TABLE.
NOTE: The data set WORK.NULL has 1 observations and 2 variables.

NOTE: CALL EXECUTE generated line.
1   + proc compare base=t1        compare=t2 noprint;   run;

NOTE: There were 3 observations read from the data set WORK.T1.
NOTE: There were 4 observations read from the data set WORK.T2.

2   + proc compare base=t1        compare=t2 noprint;   run;

NOTE: There were 3 observations read from the data set WORK.T1.
NOTE: There were 4 observations read from the data set WORK.T2.
&lt;/PRE&gt;
&lt;P&gt;So your macro reference to &amp;amp;sysinfo is resolved before the PROC COMPARE has run.&amp;nbsp; Which is not what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To prevent this timing problem, you can add a macro quoting function, %NRSTR() to the call execute.&amp;nbsp; This prevents CALL EXECUTE from actually executing the macro.&amp;nbsp; Instead, call execute will generate the macro call, and put the macro call on the input stack.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then after the data _null_ step has completed, each macro call will be executed, and the the timing works out because the PROC COMPARE can be run before the %PUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So changing the code to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data null;
set compare_table;
call execute('%nrstr(%compar)(' || a||','||b||',comment=macro invoke from data step)');
call execute('%nrstr(%compar)(t1,t2,comment=macro invoke from data step full copy)');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Gives a log:&lt;/P&gt;
&lt;PRE&gt;65   data null;
66   set compare_table;
67   call execute('%nrstr(%compar)(' || a||','||b||',comment=macro invoke from data step)');
68   call execute('%nrstr(%compar)(t1,t2,comment=macro invoke from data step full copy)');
69   run;

NOTE: There were 1 observations read from the data set WORK.COMPARE_TABLE.
NOTE: The data set WORK.NULL has 1 observations and 2 variables.

NOTE: CALL EXECUTE generated line.
1   + %compar(t1      ,t2      ,comment=macro invoke from data step)

NOTE: There were 3 observations read from the data set WORK.T1.
NOTE: There were 4 observations read from the data set WORK.T2.

WARNING: macro invoke from data step SYSINFO=128
2   + %compar(t1,t2,comment=macro invoke from data step full copy)

NOTE: There were 3 observations read from the data set WORK.T1.
NOTE: There were 4 observations read from the data set WORK.T2.

WARNING: macro invoke from data step full copy SYSINFO=128
&lt;/PRE&gt;
&lt;P&gt;While adding the %NRSTR() to the code makes it a tiny bit harder to read, it makes your log much cleaner, because you can see the only lines in the log generated by the call execute (with the + prefix) are the macro calls themselves, not the SAS code from executing the macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding %NRSTR() allows call execute to generate macro calls and place them on the input stack for execution, rather than execute the macro while the DATA _NULL_ step is running.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 13:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-in-call-execute-in-data-step/m-p/605725#M175805</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-11-20T13:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: PROC COMPARE in call execute in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-in-call-execute-in-data-step/m-p/605732#M175808</link>
      <description>Thank you greatly</description>
      <pubDate>Wed, 20 Nov 2019 13:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-in-call-execute-in-data-step/m-p/605732#M175808</guid>
      <dc:creator>i_Van</dc:creator>
      <dc:date>2019-11-20T13:43:10Z</dc:date>
    </item>
  </channel>
</rss>

