<?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: Breadcrumb trail of nested macro functions in log when mprintnest or mlogicnest options are enab in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Breadcrumb-trail-of-nested-macro-functions-in-log-when/m-p/669349#M200780</link>
    <description>&lt;P&gt;I don't know that this is exactly what you are looking for, but hopefully it is a good start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two things you can use to pull back the current macro being executed. First is the %sysmexecdepth SAS macro which will pull back a whole number representing the current "depth" of the macro being executed. Second is the %sysmexecname SAS macro which will pull back the name of the macro at a given depth.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* ------ 
 * Define test macro 1
 * ------ */
%macro mac_level_1;
	%put NOTE: This is macro 1;
	%put System Defined Level: %sysmexecdepth;
	%put System Defined Macro: %sysmexecname(%sysmexecdepth);
	
	%mac_level_2;
%mend mac_level_1;

/* ------
 * Define test macro 2
 * ------ */
%macro mac_level_2;
	%put NOTE: This is macro 2;
	%put System Defined Level: %sysmexecdepth;
	%put System Defined Macro: %sysmexecname(%sysmexecdepth);

%mend mac_level_2;

/* ------
 * Call test macro 1 (which will call test macro 2) 
 * ------ */
%mac_level_1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The %sysmexecname macro requires a numeric input, which will output the name of the macro at that level. Below is the log from executing the above code:&lt;/P&gt;
&lt;PRE&gt;43         %mac_level_1;
NOTE: This is macro 1
System Defined Level:1
System Defined Macro:MAC_LEVEL_1
NOTE: This is macro 2
System Defined Level:2
System Defined Macro:MAC_LEVEL_2
44         &lt;/PRE&gt;
&lt;P&gt;You should be able to use these system macros, in a loop, to output something along the lines of&amp;nbsp;&lt;EM&gt;MAC_LEVEL1.MAC_LEVEL_2&lt;/EM&gt;&amp;nbsp; with a loop like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i = 1 %to %sysmexecdepth;
    %sysmexecname(&amp;amp;i);
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Documentation for SAS macros:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n19g3xotkajctbn1tujf4pce6n3d.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n19g3xotkajctbn1tujf4pce6n3d.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n19g1rkeq1al87n1djihhoec4oxp.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n19g1rkeq1al87n1djihhoec4oxp.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jul 2020 01:32:30 GMT</pubDate>
    <dc:creator>agannon</dc:creator>
    <dc:date>2020-07-15T01:32:30Z</dc:date>
    <item>
      <title>Breadcrumb trail of nested macro functions in log when mprintnest or mlogicnest options are enabled</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Breadcrumb-trail-of-nested-macro-functions-in-log-when/m-p/668491#M200394</link>
      <description>&lt;P&gt;I'm working on a macro function to append a record to a SAS data set every time a specific function is called, and I need to include information on the context from which it was called.&amp;nbsp; Is there a way to programmatically access the 'breadcrumb' trail that appears in the log when mprintnest or mlogicnest options are enabled?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the 'mlogicnest' option enabled in the log excerpt below, it's clear that I've called the 'send_message' macro function which in turn calls the 'test_macro' macro function.&amp;nbsp; Using 'put _all_;' from that inner function shows me (among many others) macro variables available in the 'send_message' scope, and the automatic macro variable 'sysmacroname' shows that the current macro function is named 'test_macro'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there another place to look for the whole breadcrumb trail? or do I have to construct it as I traverse the nested macro function tree?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;BR /&gt;David&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;86 %send_message(&lt;BR /&gt;MLOGIC(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): Beginning execution.&lt;BR /&gt;87 message_dest = WORK.message_log,&lt;BR /&gt;88 message_type = exception,&lt;BR /&gt;89 message_user = david&lt;BR /&gt;90 )&lt;BR /&gt;MLOGIC(&lt;STRONG&gt;&lt;FONT color="#993300"&gt;SEND_MESSAGE&lt;/FONT&gt;&lt;/STRONG&gt;): Parameter MESSAGE_DEST has value WORK.message_log&lt;BR /&gt;MLOGIC(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): Parameter MESSAGE_TYPE has value exception&lt;BR /&gt;MLOGIC(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): Parameter MESSAGE_USER has value david&lt;BR /&gt;MLOGIC(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): Parameter MESSAGE_SRC has value unknown&lt;BR /&gt;MLOGIC(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): Parameter MESSAGE_TEXT has value &lt;BR /&gt;MPRINT(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): data WORK.new_message;&lt;BR /&gt;MPRINT(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): format message_timestamp_utc E8601LX.;&lt;BR /&gt;MPRINT(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): length message_type $32 message_src $128 message_user $32 message_text $256 message_exception_detail $1024;&lt;BR /&gt;MPRINT(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): message_timestamp_utc = tzones2u(datetime());&lt;BR /&gt;MPRINT(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): message_type = symget('message_type');&lt;BR /&gt;MPRINT(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): message_src=symget('message_src');&lt;BR /&gt;MPRINT(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): message_user = symget('message_user');&lt;BR /&gt;MPRINT(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): message_text = symget('message_text');&lt;BR /&gt;...&lt;BR /&gt;MLOGIC(&lt;STRONG&gt;&lt;FONT color="#993300"&gt;SEND_MESSAGE.TEST_MACRO&lt;/FONT&gt;&lt;/STRONG&gt;): Beginning execution.&lt;BR /&gt;MLOGIC(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE.TEST_MACRO&lt;/STRONG&gt;&lt;/FONT&gt;): This macro was compiled from the autocall file &lt;BR /&gt;.../macros/test_macro.sas&lt;BR /&gt;...&lt;BR /&gt;&lt;CODE class=" language-sas"&gt;MLOGIC(SEND_MESSAGE.TEST_MACRO): %PUT _all_&lt;BR /&gt;SEND_MESSAGE MESSAGE_DEST WORK.message_log
SEND_MESSAGE MESSAGE_SRC unknown
SEND_MESSAGE MESSAGE_TEXT 
SEND_MESSAGE MESSAGE_TYPE exception
&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;SEND_MESSAGE MESSAGE_USER david&lt;BR /&gt;&lt;/CODE&gt;...&lt;BR /&gt;AUTOMATIC SYSMACRONAME TEST_MACRO&lt;BR /&gt;...&lt;BR /&gt;MLOGIC(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE.TEST_MACRO&lt;/STRONG&gt;&lt;/FONT&gt;): Ending execution.&lt;BR /&gt;MLOGIC(&lt;FONT color="#993300"&gt;&lt;STRONG&gt;SEND_MESSAGE&lt;/STRONG&gt;&lt;/FONT&gt;): Ending execution.&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 22:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Breadcrumb-trail-of-nested-macro-functions-in-log-when/m-p/668491#M200394</guid>
      <dc:creator>DavidRice</dc:creator>
      <dc:date>2020-07-10T22:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Breadcrumb trail of nested macro functions in log when mprintnest or mlogicnest options are enab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Breadcrumb-trail-of-nested-macro-functions-in-log-when/m-p/669349#M200780</link>
      <description>&lt;P&gt;I don't know that this is exactly what you are looking for, but hopefully it is a good start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two things you can use to pull back the current macro being executed. First is the %sysmexecdepth SAS macro which will pull back a whole number representing the current "depth" of the macro being executed. Second is the %sysmexecname SAS macro which will pull back the name of the macro at a given depth.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* ------ 
 * Define test macro 1
 * ------ */
%macro mac_level_1;
	%put NOTE: This is macro 1;
	%put System Defined Level: %sysmexecdepth;
	%put System Defined Macro: %sysmexecname(%sysmexecdepth);
	
	%mac_level_2;
%mend mac_level_1;

/* ------
 * Define test macro 2
 * ------ */
%macro mac_level_2;
	%put NOTE: This is macro 2;
	%put System Defined Level: %sysmexecdepth;
	%put System Defined Macro: %sysmexecname(%sysmexecdepth);

%mend mac_level_2;

/* ------
 * Call test macro 1 (which will call test macro 2) 
 * ------ */
%mac_level_1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The %sysmexecname macro requires a numeric input, which will output the name of the macro at that level. Below is the log from executing the above code:&lt;/P&gt;
&lt;PRE&gt;43         %mac_level_1;
NOTE: This is macro 1
System Defined Level:1
System Defined Macro:MAC_LEVEL_1
NOTE: This is macro 2
System Defined Level:2
System Defined Macro:MAC_LEVEL_2
44         &lt;/PRE&gt;
&lt;P&gt;You should be able to use these system macros, in a loop, to output something along the lines of&amp;nbsp;&lt;EM&gt;MAC_LEVEL1.MAC_LEVEL_2&lt;/EM&gt;&amp;nbsp; with a loop like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i = 1 %to %sysmexecdepth;
    %sysmexecname(&amp;amp;i);
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Documentation for SAS macros:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n19g3xotkajctbn1tujf4pce6n3d.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n19g3xotkajctbn1tujf4pce6n3d.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n19g1rkeq1al87n1djihhoec4oxp.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n19g1rkeq1al87n1djihhoec4oxp.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2020 01:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Breadcrumb-trail-of-nested-macro-functions-in-log-when/m-p/669349#M200780</guid>
      <dc:creator>agannon</dc:creator>
      <dc:date>2020-07-15T01:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Breadcrumb trail of nested macro functions in log when mprintnest or mlogicnest options are enab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Breadcrumb-trail-of-nested-macro-functions-in-log-when/m-p/676267#M203898</link>
      <description>&lt;P&gt;Thank you for the very helpful information.&amp;nbsp; I've reviewed the macro functions that you referenced, and it does look like they'll provide the macro nesting lineage.&amp;nbsp; I started to implement them but ran into some issues where I was missing some of the nest levels, but I'll work on it a little more and update this reply as I know more.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 18:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Breadcrumb-trail-of-nested-macro-functions-in-log-when/m-p/676267#M203898</guid>
      <dc:creator>DavidRice</dc:creator>
      <dc:date>2020-08-12T18:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Breadcrumb trail of nested macro functions in log when mprintnest or mlogicnest options are enab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Breadcrumb-trail-of-nested-macro-functions-in-log-when/m-p/676296#M203908</link>
      <description>&lt;P&gt;If you want something that looks like what the MPRINT() log entries have you could use a macro like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro running_macros;
%local depth sep;
%do depth=1 %to %sysmexecdepth-1;&amp;amp;sep.%str()%sysmexecname(&amp;amp;depth)%let sep=.;%end;
%mend running_macros;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The -1 is to exclude the RUNNING_MACROS from the list.&amp;nbsp; The %str() is deal with the bug in how SAS parses strings generated by %SYSMEXECNAME() that causes the parse to "eat" any leading spaces.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;460   %macro running_macros;
461   %local depth sep;
462   %do depth=1 %to %sysmexecdepth-1;&amp;amp;sep.%str()%sysmexecname(&amp;amp;depth)%let sep=.;%end;
463   %mend running_macros;
464
465   %macro test1;
466     %put &amp;amp;sysmacroname called by %running_macros;
467   %mend;
468   %macro test2;
469     %test1;
470   %mend;
471
472   %put %running_macros;

473   %test1;
TEST1 called by TEST1
474   %test2;
TEST1 called by TEST2.TEST1&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Aug 2020 20:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Breadcrumb-trail-of-nested-macro-functions-in-log-when/m-p/676296#M203908</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-12T20:09:43Z</dc:date>
    </item>
  </channel>
</rss>

