<?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: Get program name and path when using %INCLUDE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529170#M144526</link>
    <description>&lt;P&gt;It might help to include examples of the macros or code you have attempted that don't work so you don't get those or similar suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What to want for output to this? An entry in a the LOG, a macro variable, write to a data set? Or is this supposed to parse a code file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would tend to take any of my %include statements and add the appropriate code in the main program. Such as if I wanted something in the LOG:&lt;/P&gt;
&lt;PRE&gt;%put "Calling Program: Program2.SAS in C:\Users\&amp;amp;sysuserid.\Desktop";


%include "C:\Users\&amp;amp;sysuserid.\Desktop\Program2.sas";&lt;/PRE&gt;</description>
    <pubDate>Tue, 22 Jan 2019 18:11:07 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-01-22T18:11:07Z</dc:date>
    <item>
      <title>Get program name and path when using %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529145#M144521</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for a way to dynamically retrieve the name/path of the SAS programs that are being executed (i.e. the information would remain correct if a program would be moved to a different folder and/or would be renamed), but with the specificity that the different programs are called in a sequence making use of %INCLUDE statements.&lt;BR /&gt;&lt;BR /&gt; I have found many macros doing that perfectly for the main program (i.e. the one in which the %INCLUDE statements are coded), but it does not work for the programs which are included (returned path and program names remain the names of the main program).&lt;BR /&gt;&lt;BR /&gt; I guess this is due to the fact that the %include statement only append the code of a SAS program into the program making the calling?&lt;BR /&gt;&lt;BR /&gt;I am working on SAS 9.4&amp;nbsp;on Windows 10.&lt;BR /&gt;&lt;BR /&gt;Would there be anyone who already had this need and found a solution? Here below, a representation of what I would like to get:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Main program: C:\Users\&amp;amp;sysuserid.\Desktop\Program1.sas&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;path value = C:\Users\&amp;amp;sysuserid.\Desktop&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;program name = Program1.sas&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;First include statement:&amp;nbsp; %include "&lt;SPAN&gt;C:\Users\&lt;/SPAN&gt;&lt;SPAN&gt;&amp;amp;sysuserid.&lt;/SPAN&gt;&lt;SPAN&gt;\Desktop\Program2.sas";&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;path value = C:\Users\&amp;amp;sysuserid.\Desktop&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;program name = Program2.sas&lt;BR /&gt;&lt;BR /&gt;Second include statement:&amp;nbsp; %include "D:\Program3.sas";&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;path value =&amp;nbsp;D:\&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;program name = Program3.sas&lt;BR /&gt;&lt;BR /&gt;Many thanks in advance for your help.&lt;BR /&gt;&lt;BR /&gt;Kr,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Florent&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 17:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529145#M144521</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2019-01-22T17:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: Get program name and path when using %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529170#M144526</link>
      <description>&lt;P&gt;It might help to include examples of the macros or code you have attempted that don't work so you don't get those or similar suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What to want for output to this? An entry in a the LOG, a macro variable, write to a data set? Or is this supposed to parse a code file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would tend to take any of my %include statements and add the appropriate code in the main program. Such as if I wanted something in the LOG:&lt;/P&gt;
&lt;PRE&gt;%put "Calling Program: Program2.SAS in C:\Users\&amp;amp;sysuserid.\Desktop";


%include "C:\Users\&amp;amp;sysuserid.\Desktop\Program2.sas";&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Jan 2019 18:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529170#M144526</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-22T18:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Get program name and path when using %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529218#M144534</link>
      <description>&lt;P&gt;SAS now sets that information into macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=%sysfunc(pathname(work));
data _null_;
  file "&amp;amp;path/test.sas" ;
  put '%put &amp;amp;=SYSINCLUDEFILEDEVICE;'
    / '%put &amp;amp;=SYSINCLUDEFILEDIR;'
    / '%put &amp;amp;=SYSINCLUDEFILEFILEREF;'
    / '%put &amp;amp;=SYSINCLUDEFILENAME;'
  ;
run;

%include "&amp;amp;path/test.sas" ;

filename test "&amp;amp;path/test.sas";
%include test ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;390   %include "&amp;amp;path/test.sas" ;
SYSINCLUDEFILEDEVICE=DISK
SYSINCLUDEFILEDIR=C:\...
SYSINCLUDEFILEFILEREF=
SYSINCLUDEFILENAME=test.sas
395
396   filename test "&amp;amp;path/test.sas";
397   %include test ;
SYSINCLUDEFILEDEVICE=DISK
SYSINCLUDEFILEDIR=C:\...
SYSINCLUDEFILEFILEREF=TEST
SYSINCLUDEFILENAME=test.sas
&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Jan 2019 18:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529218#M144534</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-22T18:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Get program name and path when using %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529517#M144695</link>
      <description>&lt;P&gt;Hi ballardw,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An entry in the LOG was indeed the idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, I wanted to avoid typing that kind of hard-coded %put statements in the programs because that would remain static (I am looking for a dynamic way to trace programs names and locations (in case a program would be renamed and/or moved to a different location).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reply from Tom gives exactly what I was looking for. I was just not aware that the referred automatic macro-variables were introduced in SAS 9.4 but they are pretty much handy!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Florent&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jan 2019 20:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529517#M144695</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2019-01-23T20:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: Get program name and path when using %INCLUDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529544#M144707</link>
      <description>&lt;P&gt;If you just want to see the filename in the LOG you don't have to do anything. SAS already writes a NOTE with that information.&lt;/P&gt;
&lt;PRE&gt;746   %include code /source2 ;
NOTE: %INCLUDE (level 1) file CODE is file C:\...\AppData\Local\Temp\1\SAS Temporary
      Files\_TD8300_..._\#LN00084.
747  +* Temporary file;
NOTE: %INCLUDE (level 1) ending.
&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Jan 2019 20:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-program-name-and-path-when-using-INCLUDE/m-p/529544#M144707</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-23T20:56:07Z</dc:date>
    </item>
  </channel>
</rss>

