<?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: How to detect if my code is being called inside a %INCLUDE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765813#M242603</link>
    <description>&lt;P&gt;Oh, I see. I'm sorry.&lt;BR /&gt;The SAS Programming Documentation I referred to did not mention that limitation, even though it is the same version.&lt;/P&gt;
&lt;P&gt;I should have referred to the original, English version.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Sep 2021 08:34:46 GMT</pubDate>
    <dc:creator>japelin</dc:creator>
    <dc:date>2021-09-03T08:34:46Z</dc:date>
    <item>
      <title>How to detect if my code is being called inside a %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765566#M242498</link>
      <description>&lt;P&gt;I am looking for a way to detect (at runtime) if my SAS code is being executed inside of (as part of / within) a %INCLUDE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this possible?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 07:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765566#M242498</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2021-09-02T07:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect if my code is being called inside a %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765568#M242500</link>
      <description>&lt;P&gt;I guess it depends on whether you want to detect it during execution, or whether you want to detect it after the submitted steps are all completed.&lt;BR /&gt;If it is the latter, you can use %include with the source2 option to output to the log, so you can check the log saved in an external file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, what action do you expect to take when it is detected?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 08:06:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765568#M242500</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-09-02T08:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect if my code is being called inside a %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765571#M242502</link>
      <description>I'm talking about runtime (during execution).&lt;BR /&gt;&lt;BR /&gt;Our error handling macro needs to act differently when called inside a %include, due to differences in the way SAS processes macros in this context.</description>
      <pubDate>Thu, 02 Sep 2021 08:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765571#M242502</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2021-09-02T08:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect if my code is being called inside a %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765573#M242504</link>
      <description>&lt;P&gt;Why not use the SYSINCLUDEFILEDIR and SYSINCLUDEFILENAME Automatic Macro Variables?&lt;BR /&gt;Those will contain the directory and file name of the called program when it is submitted in %include.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 08:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765573#M242504</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-09-02T08:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect if my code is being called inside a %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765574#M242505</link>
      <description>&lt;P&gt;perfect! thankyou!! I didn't see those...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For reference, these are the results I got:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

filename _test temp;
data _null_;
  file _test;
  put '%put &amp;amp;=SYSINCLUDEFILEDIR;';
  put '%put &amp;amp;=SYSINCLUDEFILEDEVICE;';
  put '%put &amp;amp;=SYSINCLUDEFILEFILEREF;';
  put '%put &amp;amp;=SYSINCLUDEFILENAME;';
run;

%inc _test;

%macro x();
%let loc="%sysfunc(pathname(work))/test";
data _null_;
  file &amp;amp;loc;
  put '%put &amp;amp;=SYSINCLUDEFILEDIR;';
  put '%put &amp;amp;=SYSINCLUDEFILEDEVICE;';
  put '%put &amp;amp;=SYSINCLUDEFILEFILEREF;';
  put '%put &amp;amp;=SYSINCLUDEFILENAME;';
run;

%inc &amp;amp;loc;
%mend;

%x()

%put &amp;amp;=SYSINCLUDEFILEDIR;
%put &amp;amp;=SYSINCLUDEFILEDEVICE;
%put &amp;amp;=SYSINCLUDEFILEFILEREF;
%put &amp;amp;=SYSINCLUDEFILENAME;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         
 74         
 75         filename _test temp;
 76         data _null_;
 77           file _test;
 78           put '%put &amp;amp;=SYSINCLUDEFILEDIR;';
 79           put '%put &amp;amp;=SYSINCLUDEFILEDEVICE;';
 80           put '%put &amp;amp;=SYSINCLUDEFILEFILEREF;';
 81           put '%put &amp;amp;=SYSINCLUDEFILENAME;';
 82         run;
 
 NOTE: The file _TEST is:
       Filename=/tmp/SAS_work55E900003774_sas.analytium.co.uk/#LN00187,
       Owner Name=allbow,Group Name=allbow,
       Access Permission=-rw-r--r--,
       Last Modified=02 September 2021 11:46:51
 
 NOTE: 4 records were written to the file _TEST.
       The minimum record length was 25.
       The maximum record length was 29.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              473.00k
       OS Memory           26276.00k
       Timestamp           02/09/2021 08:46:51 AM
       Step Count                        72  Switch Count  0
       Page Faults                       0
       Page Reclaims                     62
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           8
       
 
 83         
 84         %inc _test;
 SYSINCLUDEFILEDIR=/tmp/SAS_work55E900003774_sas.analytium.co.uk
 SYSINCLUDEFILEDEVICE=TEMP
 SYSINCLUDEFILEFILEREF=_TEST
 SYSINCLUDEFILENAME=#LN00187
 89         
 90         %macro x();
 91         %let loc="%sysfunc(pathname(work))/test";
 92         data _null_;
 93           file &amp;amp;loc;
 94           put '%put &amp;amp;=SYSINCLUDEFILEDIR;';
 95           put '%put &amp;amp;=SYSINCLUDEFILEDEVICE;';
 96           put '%put &amp;amp;=SYSINCLUDEFILEFILEREF;';
 97           put '%put &amp;amp;=SYSINCLUDEFILENAME;';
 98         run;
 99         
 100        %inc &amp;amp;loc;
 101        %mend;
 102        
 103        %x()
 
 NOTE: The file "/tmp/SAS_work55E900003774_sas.analytium.co.uk/SAS_work810D00003774_sas.analytium.co.uk/test" is:
       Filename=/tmp/SAS_work55E900003774_sas.analytium.co.uk/SAS_work810D00003774_sas.analytium.co.uk/test,
       Owner Name=allbow,Group Name=allbow,
       Access Permission=-rw-r--r--,
       Last Modified=02 September 2021 11:46:51
 
 NOTE: 4 records were written to the file 
       "/tmp/SAS_work55E900003774_sas.analytium.co.uk/SAS_work810D00003774_sas.analytium.co.uk/test".
       The minimum record length was 25.
       The maximum record length was 29.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              469.37k
       OS Memory           26276.00k
       Timestamp           02/09/2021 08:46:51 AM
       Step Count                        73  Switch Count  0
       Page Faults                       0
       Page Reclaims                     25
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           8
       
 
 SYSINCLUDEFILEDIR=/tmp/SAS_work55E900003774_sas.analytium.co.uk/SAS_work810D00003774_sas.analytium.co.uk
 SYSINCLUDEFILEDEVICE=DISK
 SYSINCLUDEFILEFILEREF=
 SYSINCLUDEFILENAME=test
 108        
 109        %put &amp;amp;=SYSINCLUDEFILEDIR;
 SYSINCLUDEFILEDIR=
 110        %put &amp;amp;=SYSINCLUDEFILEDEVICE;
 SYSINCLUDEFILEDEVICE=
 111        %put &amp;amp;=SYSINCLUDEFILEFILEREF;
 SYSINCLUDEFILEFILEREF=�|��#
 112        %put &amp;amp;=SYSINCLUDEFILENAME;
 SYSINCLUDEFILENAME=
 113        
 114        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 126        
&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Sep 2021 10:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765574#M242505</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2021-09-02T10:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect if my code is being called inside a %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765805#M242596</link>
      <description>&lt;P&gt;So in the end this did NOT fix my use case - as those macro variables are NOT available inside of macros!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;SYSINCLUDEFILEDEVICE&lt;/LI&gt;
&lt;LI&gt;SYSINCLUDEFILEDIR&lt;/LI&gt;
&lt;LI&gt;SYSINCLUDEFILEFILEREF&lt;/LI&gt;
&lt;LI&gt;SYSINCLUDEFILENAME&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To deal with this scenario, I made a macro wrapper for the %include statement, that inserts these variables as precode - it's documented here:&amp;nbsp; &lt;A href="https://core.sasjs.io/mp__include_8sas.html" target="_blank"&gt;https://core.sasjs.io/mp__include_8sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 08:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765805#M242596</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2021-09-03T08:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect if my code is being called inside a %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765813#M242603</link>
      <description>&lt;P&gt;Oh, I see. I'm sorry.&lt;BR /&gt;The SAS Programming Documentation I referred to did not mention that limitation, even though it is the same version.&lt;/P&gt;
&lt;P&gt;I should have referred to the original, English version.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 08:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765813#M242603</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-09-03T08:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect if my code is being called inside a %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765816#M242605</link>
      <description>Your input led to the solution!  No need to apologise.  It's a strange limitation indeed, or at least, not intuitive.  The best thing is, we finally have a way to allow end users to send custom abort messages from the user provided validation programs in our main product - Data Controller for SAS&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://datacontroller.io" target="_blank"&gt;https://datacontroller.io&lt;/A&gt;</description>
      <pubDate>Fri, 03 Sep 2021 09:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-detect-if-my-code-is-being-called-inside-a-INCLUDE/m-p/765816#M242605</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2021-09-03T09:24:38Z</dc:date>
    </item>
  </channel>
</rss>

