<?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: Differences in behavior depending on where the macro reference is executed in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782412#M249418</link>
    <description>I know that we can get rid of it by using double quotation marks.&lt;BR /&gt;I don't want it to be resolved at the time of storing it in the variable res, so I use single quotation marks.</description>
    <pubDate>Thu, 25 Nov 2021 09:15:18 GMT</pubDate>
    <dc:creator>japelin</dc:creator>
    <dc:date>2021-11-25T09:15:18Z</dc:date>
    <item>
      <title>Differences in behavior depending on where the macro reference is executed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782401#M249410</link>
      <description>&lt;P&gt;In the following two macro codes (Mtest1 and Mtest2), the process itself looks the same, but when I submit, the macro reference cannot be resolved in Mtest1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro Mtest1(XXX);
  res=resolve('&amp;amp;XXX');
%Mend;
data _null_;
  %Mtest1(abc);
run;

 

%Macro Mtest2(XXX);
data _null_;
  res=resolve('&amp;amp;XXX');
run;
%Mend;
%Mtest2(abc);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="2021-11-25_16h24_46.png" style="width: 376px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66093i4BAA00098579DA7D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2021-11-25_16h24_46.png" alt="2021-11-25_16h24_46.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know how to resolve it.&lt;BR /&gt;All I have to do is change the single quotes to double quotes. (This may not be appropriate in this case, since it eliminates the need for the resolve function.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway. I don't understand why there is such a difference between executing a macro reference in the data step and in the open code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Nov 2021 07:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782401#M249410</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-11-25T07:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: Differences in behavior depending on where the macro reference is executed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782409#M249415</link>
      <description>&lt;P&gt;Why are you using resolve? symget is the function to use if you want to resolve a macro-variable.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Nov 2021 07:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782409#M249415</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-11-25T07:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Differences in behavior depending on where the macro reference is executed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782410#M249416</link>
      <description>&lt;P&gt;Do you understand now?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro Mtest1(XXX);
  length res $50;
  res=resolve("&amp;amp;XXX");
  put res=;
%Mend;
data _null_;
  %Mtest1(abc);
run;

 

%Macro Mtest2(XXX);
data _null_;
  length res $50;
  res=resolve("&amp;amp;XXX");
  put res=;
run;
%Mend;
%Mtest2(abc);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Nov 2021 08:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782410#M249416</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-11-25T08:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Differences in behavior depending on where the macro reference is executed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782411#M249417</link>
      <description>Originally, I wanted to create a macro variable by combining the value of the macro variable specified in the parameter with the value stored in the dataset variable.&lt;BR /&gt;For this reason, I used resolve instead of symget.&lt;BR /&gt;Besides, even with symget, I encounter a similar problem to the first code I presented.</description>
      <pubDate>Thu, 25 Nov 2021 09:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782411#M249417</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-11-25T09:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Differences in behavior depending on where the macro reference is executed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782412#M249418</link>
      <description>I know that we can get rid of it by using double quotation marks.&lt;BR /&gt;I don't want it to be resolved at the time of storing it in the variable res, so I use single quotation marks.</description>
      <pubDate>Thu, 25 Nov 2021 09:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782412#M249418</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-11-25T09:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Differences in behavior depending on where the macro reference is executed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782414#M249419</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226565"&gt;@japelin&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n0xmqcv92coq2tn1k0z0q6fl2dew.htm" target="_blank" rel="noopener"&gt;MLOGIC system option&lt;/A&gt;&amp;nbsp;helps to see what's going on: Macro parameters such as XXX are &lt;EM&gt;local&lt;/EM&gt; macro variables, which exist only during macro execution. Therefore, the RESOLVE function in the DATA step can resolve&amp;nbsp;'&amp;amp;XXX' only if it is executed &lt;EM&gt;during&lt;/EM&gt; macro execution. With MLOGIC in effect, start and end of macro execution are documented in the log and we can see whether the DATA step execution occurs during&amp;nbsp;macro execution.&amp;nbsp;The RUN statement triggers DATA step execution. By putting the RUN statement into the macro as in your Mtest2 or in macro Mtest3 below we can ensure that the DATA step executes during macro execution. Macro Mtest4 below carries this to extremes by just providing the closing semicolon of the RUN statement.&lt;/P&gt;
&lt;PRE&gt;2    options mlogic;
3
4    %Macro Mtest1(XXX);
5      res=resolve('&amp;amp;XXX');
6    %Mend;
7    data _null_;
8      %Mtest1(abc);
&lt;STRONG&gt;MLOGIC(MTEST1):  Beginning execution.
&lt;/STRONG&gt;MLOGIC(MTEST1):  Parameter XXX has value abc
&lt;STRONG&gt;MLOGIC(MTEST1):  Ending execution.&lt;/STRONG&gt;
9    run;

&lt;FONT color="#008000"&gt;WARNING: Apparent symbolic reference XXX not resolved.&lt;/FONT&gt;
&lt;FONT color="#3366FF"&gt;NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds&lt;/FONT&gt;


10
11   %Macro Mtest2(XXX);
12   data _null_;
13     res=resolve('&amp;amp;XXX');
14   run;
15   %Mend;
16   %Mtest2(abc);
&lt;STRONG&gt;MLOGIC(MTEST2):  Beginning execution.&lt;/STRONG&gt;
MLOGIC(MTEST2):  Parameter XXX has value abc

&lt;FONT color="#3366FF"&gt;NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/FONT&gt;


&lt;STRONG&gt;MLOGIC(MTEST2):  Ending execution.&lt;/STRONG&gt;
17
18   %Macro Mtest3(XXX);
19     run;
20   %Mend;
21
22   data _null_;
23   res=resolve('&amp;amp;XXX');
24   put res=;
25   %Mtest3(abc)
&lt;STRONG&gt;MLOGIC(MTEST3):  Beginning execution.&lt;/STRONG&gt;
MLOGIC(MTEST3):  Parameter XXX has value abc

res=abc
&lt;FONT color="#3366FF"&gt;NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/FONT&gt;


&lt;STRONG&gt;MLOGIC(MTEST3):  Ending execution.&lt;/STRONG&gt;
26
27   %Macro Mtest4(XXX);
28     ;
29   %Mend;
30
31   data _null_;
32   res=resolve('&amp;amp;XXX');
33   put res=;
34   run
&lt;STRONG&gt;MLOGIC(MTEST4):  Beginning execution.&lt;/STRONG&gt;
35   %Mtest4(abc)
MLOGIC(MTEST4):  Parameter XXX has value abc

res=abc
&lt;FONT color="#3366FF"&gt;NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/FONT&gt;


&lt;STRONG&gt;MLOGIC(MTEST4):  Ending execution.&lt;/STRONG&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Nov 2021 09:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782414#M249419</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-11-25T09:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Differences in behavior depending on where the macro reference is executed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782415#M249420</link>
      <description>&lt;P&gt;ok so, depending of what you exactly want to do, you do not need to resolve if you want to append the values;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let test=abc;
data _NULL_;
   a='jfk';
   b=cats(a,"&amp;amp;test.");
   put b=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Besides that, you need to understand when a macro variable resolves and when not. Use the MLOGIC, MPRINT and SYMBOLGEN options to trace how SAS proceeds:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS MLOGIC MPRINT SYMBOLGEN;
%Macro Mtest1(XXX);
  res=resolve('&amp;amp;XXX');
%Mend;
data _null_;
  %Mtest1(abc);
  put res=;
run;

 
%SYMDEL XXX;
%Macro Mtest2(XXX);
data _null_;
  res=resolve('&amp;amp;XXX');
  put res=;
run;
%Mend;
%Mtest2(abc);
OPTIONS NOMLOGIC NOMPRINT NOSYMBOLGEN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro functionality is processed first, that means that your first step is identical with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  res=resolve('&amp;amp;XXX');
  put res=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since XXX is not defined in your environment SAS yells a warning.&lt;/P&gt;
&lt;P&gt;In your second step, the XXX already exist before it is processed by the datastep and therefore runs perfectly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For advance data driven processing, check this &lt;A href="https://blogs.sas.com/content/sgf/2017/08/02/call-execute-for-sas-data-driven-programming/" target="_blank" rel="noopener"&gt;blog&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;You may be especially interested in the combination of use of CALL EXECUTE and macro call.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Nov 2021 09:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Differences-in-behavior-depending-on-where-the-macro-reference/m-p/782415#M249420</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-11-25T09:58:34Z</dc:date>
    </item>
  </channel>
</rss>

