<?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: Why won't SYSINCLUDEFILENAME resolve inside a macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-won-t-SYSINCLUDEFILENAME-resolve-inside-a-macro/m-p/843947#M333643</link>
    <description>&lt;P&gt;My new theory is that when code is generated (e.g. by the macro processor executing a macro), SYSINCLUDEFILENAME is not assigned a value. So in order for SYSINCLUDEFILENAME to have a value, it means tokens are literally being read from the %include file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried CALL EXECUTE.&amp;nbsp; If you %INCLUDE a file that uses CALL EXECUTE to generate a PUT statement to resolve SYSINCLUDEFILENAME, it also returns null.&amp;nbsp; So my guess is the limitation is in the method used to assign a value to SYSINCLUDEFILENAME.&amp;nbsp; I think it sees code that has been generated (by some code in the include file) as not being code that came from the current include file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I'm happier with this being an issue with how/when SYSINCLUDEFILENAME is given a value, rather than it being an issue with the macro language not being able to resolve a a macro variable.&amp;nbsp; And it also fits with the original example.&amp;nbsp; It's not really that the macro variable does not resolve (which is what the docs says, imprecisely).&amp;nbsp; It's that the macro variable resolves to a null value, which is indeed the value of the macro variable when there is no current %include file.&amp;nbsp; That said, I still don't understand why %put _automatic_ inside a macro would show that SYSINCLUDEFILENAME has a value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My call execute test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code "%sysfunc(pathname(work))/myinclude.sas";

data _null_ ;
  file code ;
  put
/'data null ; '
/' put "Non-generated code sysincludefilename=&amp;amp;sysincludefilename sysvlong=&amp;amp;sysvlong" ; '
/' call execute(''data _null_ ; put "Generated code sysincludefilename=&amp;amp;sysincludefilename sysvlong=&amp;amp;sysvlong" ; run ;'') ;'
/'run ;'
  ;
run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Returns:&lt;/P&gt;
&lt;PRE&gt;13   %include code / source2;
NOTE: %INCLUDE (level 1) file CODE is file C:\Users\Q\AppData\Local\Temp\SAS Temporary
      Files\_TD1036_MD3V5PHC_\myinclude.sas.
14  +
15  +data null ;
16  + put "Non-generated code sysincludefilename=&amp;amp;sysincludefilename sysvlong=&amp;amp;sysvlong" ;
17  + call execute('data _null_ ; put "Generated code sysincludefilename=&amp;amp;sysincludefilename
17 !+sysvlong=&amp;amp;sysvlong" ; run ;') ;
18  +run ;

Non-generated code sysincludefilename=myinclude.sas sysvlong=9.04.01M7P080520
NOTE: The data set WORK.NULL has 1 observations and 0 variables.

NOTE: CALL EXECUTE generated line.
1   + data _null_ ; put "Generated code sysincludefilename= sysvlong=9.04.01M7P080520" ; run ;

Generated code sysincludefilename= sysvlong=9.04.01M7P080520

NOTE: %INCLUDE (level 1) ending.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 12 Nov 2022 19:31:05 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2022-11-12T19:31:05Z</dc:date>
    <item>
      <title>Why won't SYSINCLUDEFILENAME resolve inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-won-t-SYSINCLUDEFILENAME-resolve-inside-a-macro/m-p/843873#M333615</link>
      <description>&lt;P&gt;There is a documented oddity that the automatic macro variable SYSINCLUDEFILENAME won't resolve inside a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The docs say:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;TABLE class="xisDoc-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="xisDoc-restriction"&gt;Restriction:&lt;/TH&gt;
&lt;TD class="xisDoc-summaryText"&gt;This variable does not resolve in a macro definition that is included with the %INCLUDE statement. To resolve in included code, the reference must be outside of a macro definition. See&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A tabindex="0" href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1j5tcc0n2xczyn1kg1o0606gsv9.htm#p1awqvemugphren14govpqz2a4bv" target="_blank"&gt;Using the SYSINCLUDEFILE Automatic Macro Variables in Included Macro Definitions&lt;/A&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n19hjgfztbsglan14ekohdzq5s97.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n19hjgfztbsglan14ekohdzq5s97.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While the docs suggest the problem relates to the macro definition being in the %included file, it also happens when just the macro call is in an %included file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone understand why this would happen?&amp;nbsp; I've never known a macro variable that exists in a symbol table but can't be resolved when a macro executes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I played with it a little, and found that even though the reference to SYSINCLUDEFILENAME won't resolve (or maybe it resolves to null), if you use %put _automatic_ inside a macro, it will show that the automatic macro variable SYSINCLUDEFILENAME has a value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this means it's there in the symbol table (assuming we can trust that %put _automatic_ isn't doing any trickery to make it appear), but for some reason it can't be resolved.&amp;nbsp; This doesn't make any sense to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, I know it's documented.&amp;nbsp; But trying to understand oddities like this sometimes provide insights into the inner workings of the macro language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My test code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro try() ;
  %put Inside Macro sysincludefilename is empty: &amp;amp;=sysincludefilename ;
  %put ;

  %put But %nrstr(%%)put _automatic_ in the macro shows sysincludefilename has a value ;
  %put _automatic_ ;
%mend try ;

filename code "%sysfunc(pathname(work))/myinclude.sas";

data _null_ ;
  file code ;
  put
 '%put Open Code: &amp;amp;=sysincludefilename ;'
/'%try()'
  ;
run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 23:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-won-t-SYSINCLUDEFILENAME-resolve-inside-a-macro/m-p/843873#M333615</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-11-11T23:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Why won't SYSINCLUDEFILENAME resolve inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-won-t-SYSINCLUDEFILENAME-resolve-inside-a-macro/m-p/843876#M333616</link>
      <description>&lt;P&gt;Without knowing how SAS actually works internally we can only guess.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either it was on purpose for some reason, or it was a side effect of how include files and macro calls work and they decided rather than change it to just document the behavior.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is also not there in the SASHELP.VMACRO values for while a macro is running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need it in the macro you need to push it in when you CALL the macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro try(caller) ;
  %put Inside Macro sysincludefilename is empty: &amp;amp;=sysincludefilename &amp;amp;=caller;
%mend try ;

filename code temp;

data _null_ ;
  file code ;
  put
 '%put Open Code: &amp;amp;=sysincludefilename ;'
/'%try(&amp;amp;sysincludefilename)'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Nov 2022 00:51:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-won-t-SYSINCLUDEFILENAME-resolve-inside-a-macro/m-p/843876#M333616</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-12T00:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why won't SYSINCLUDEFILENAME resolve inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-won-t-SYSINCLUDEFILENAME-resolve-inside-a-macro/m-p/843947#M333643</link>
      <description>&lt;P&gt;My new theory is that when code is generated (e.g. by the macro processor executing a macro), SYSINCLUDEFILENAME is not assigned a value. So in order for SYSINCLUDEFILENAME to have a value, it means tokens are literally being read from the %include file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried CALL EXECUTE.&amp;nbsp; If you %INCLUDE a file that uses CALL EXECUTE to generate a PUT statement to resolve SYSINCLUDEFILENAME, it also returns null.&amp;nbsp; So my guess is the limitation is in the method used to assign a value to SYSINCLUDEFILENAME.&amp;nbsp; I think it sees code that has been generated (by some code in the include file) as not being code that came from the current include file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I'm happier with this being an issue with how/when SYSINCLUDEFILENAME is given a value, rather than it being an issue with the macro language not being able to resolve a a macro variable.&amp;nbsp; And it also fits with the original example.&amp;nbsp; It's not really that the macro variable does not resolve (which is what the docs says, imprecisely).&amp;nbsp; It's that the macro variable resolves to a null value, which is indeed the value of the macro variable when there is no current %include file.&amp;nbsp; That said, I still don't understand why %put _automatic_ inside a macro would show that SYSINCLUDEFILENAME has a value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My call execute test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code "%sysfunc(pathname(work))/myinclude.sas";

data _null_ ;
  file code ;
  put
/'data null ; '
/' put "Non-generated code sysincludefilename=&amp;amp;sysincludefilename sysvlong=&amp;amp;sysvlong" ; '
/' call execute(''data _null_ ; put "Generated code sysincludefilename=&amp;amp;sysincludefilename sysvlong=&amp;amp;sysvlong" ; run ;'') ;'
/'run ;'
  ;
run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Returns:&lt;/P&gt;
&lt;PRE&gt;13   %include code / source2;
NOTE: %INCLUDE (level 1) file CODE is file C:\Users\Q\AppData\Local\Temp\SAS Temporary
      Files\_TD1036_MD3V5PHC_\myinclude.sas.
14  +
15  +data null ;
16  + put "Non-generated code sysincludefilename=&amp;amp;sysincludefilename sysvlong=&amp;amp;sysvlong" ;
17  + call execute('data _null_ ; put "Generated code sysincludefilename=&amp;amp;sysincludefilename
17 !+sysvlong=&amp;amp;sysvlong" ; run ;') ;
18  +run ;

Non-generated code sysincludefilename=myinclude.sas sysvlong=9.04.01M7P080520
NOTE: The data set WORK.NULL has 1 observations and 0 variables.

NOTE: CALL EXECUTE generated line.
1   + data _null_ ; put "Generated code sysincludefilename= sysvlong=9.04.01M7P080520" ; run ;

Generated code sysincludefilename= sysvlong=9.04.01M7P080520

NOTE: %INCLUDE (level 1) ending.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Nov 2022 19:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-won-t-SYSINCLUDEFILENAME-resolve-inside-a-macro/m-p/843947#M333643</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-11-12T19:31:05Z</dc:date>
    </item>
  </channel>
</rss>

