<?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: Use relative path to run SAS programs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/283239#M57712</link>
    <description>&lt;P&gt;I am not sure if Enterprise Guide sends anything to the SAS server to let it know what piece of SAS code it is currently running. &amp;nbsp; Someone with more EG experience might be able to comment on that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to look into using a code management or version control tools that will let you automatically embed the path INTO the file when you move it. For example if you use RCS then you can use the $SOURCE keyword to have RCS store the location of the file into the file when new versions are checked into the version control system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also change how you are calling the program. &amp;nbsp;In stead of pointing and clicking at a file just submit a small program the calls the program you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=...... ;
%include "&amp;amp;path/test.sas";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then the program "test.sas" that is called can assume that the macro variable PATH has already been set and use that to find the other programs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way is to change how your code is organized so that you can use AUTOCALL macros instead of %INCLUDING files with code in them. &amp;nbsp;Then you can just adjust the path used in the SASAUTOS option and SAS will find and automatically include the macro definition when you call your system macros. &amp;nbsp;Then your programsn look more like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%part1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include '../../part1.sas';
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Jul 2016 01:03:37 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-07-11T01:03:37Z</dc:date>
    <item>
      <title>Use relative path to run SAS programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/282742#M57505</link>
      <description>&lt;P&gt;Is there a way I can use relative path in SAS program? Something like, if I have a SAS code in test &amp;gt; test1&amp;gt; test2 directory calles test.sas and the content of test.sas is as below. I want to execute the program path.sas which is in test folder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%include "..\..\path.sas";&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 17:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/282742#M57505</guid>
      <dc:creator>KBACHU</dc:creator>
      <dc:date>2016-07-07T17:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Use relative path to run SAS programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/282747#M57508</link>
      <description>&lt;P&gt;Can you? Yes. But considering the the default run location is a bit variable as a temporary folder that gets deleted when SAS terminates then it is a poor idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do not want to retype a long path, or make it easy to change you could use a macro variable in an autoexec.sas to set the long part and then use as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let basepath= c:\data\folder1\test1\test2\test3\;&amp;nbsp; /* note that this has to be valid per your operating system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%include "&amp;amp;basepath.program1.sas";&lt;/P&gt;
&lt;P&gt;would bring the code from program1.sas file into the current program from the folder indicated by the BASEPATH macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To change location just modify the %let statement for Basepath.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 16:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/282747#M57508</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-05T16:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Use relative path to run SAS programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/282759#M57512</link>
      <description>&lt;P&gt;Relative file paths in SAS are relative to the 'current directory'. If you want a path that is relative to the path of the current program, you have to build it yourself.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get the path of the current program, use SYSGET("SAS_EXECFILEPATH") in a data step or %qsysfunc(sysget(SAS_EXECFILEPATH)) in macro code.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 18:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/282759#M57512</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-07-07T18:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: Use relative path to run SAS programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/283234#M57707</link>
      <description>&lt;P&gt;Thanks for your respone. Can you please give me an example? The relative path doesnt work from EG. We have a procedure in which we move the SAS code to different enviornments. Using relative path will make our life easier as we dont have to modify the program path everytime we migrate the code. I even tried using X in front of the %include statement, but for some reasons SAS coesnt recognize the file.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 00:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/283234#M57707</guid>
      <dc:creator>KBACHU</dc:creator>
      <dc:date>2016-07-11T00:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Use relative path to run SAS programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/283236#M57709</link>
      <description>&lt;P&gt;You can easily use relative paths if you run SAS from the command line. For example in Unix environment. &amp;nbsp;But if you are launching SAS in other ways then you will need to have some way to tell SAS what directory you want to use for your base path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you store the path into a macro variable then you can use that to generate the file names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rundir = /root/test/test1/test2 ;
%include "&amp;amp;rundir/../../path.sas";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can even use SAS filerefs instead of macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename rundir '/root/test/test1/test2' ;
%include rundir('../../path.sas');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jul 2016 00:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/283236#M57709</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-11T00:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Use relative path to run SAS programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/283237#M57710</link>
      <description>&lt;P&gt;Thanks Tom for your reply. I would like to use this feature from SAS EG.&amp;nbsp; I will not be able to use the below variable as the top level directory will change when I move the code from one environemnt to an other. I am looking for some macro which autodetects the current folder and able to execute the code which is two levels below the current directory using the include statment. I was able to acheive this by running SAS on compute server directly by using %include '..\..\..', but this feature doesnt work from EG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; rundir &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;root&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;test&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;test1&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;test2 &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token macrostatement"&gt;%include&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"&amp;amp;rundir/../../path.sas"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 00:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/283237#M57710</guid>
      <dc:creator>KBACHU</dc:creator>
      <dc:date>2016-07-11T00:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Use relative path to run SAS programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/283239#M57712</link>
      <description>&lt;P&gt;I am not sure if Enterprise Guide sends anything to the SAS server to let it know what piece of SAS code it is currently running. &amp;nbsp; Someone with more EG experience might be able to comment on that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to look into using a code management or version control tools that will let you automatically embed the path INTO the file when you move it. For example if you use RCS then you can use the $SOURCE keyword to have RCS store the location of the file into the file when new versions are checked into the version control system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also change how you are calling the program. &amp;nbsp;In stead of pointing and clicking at a file just submit a small program the calls the program you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=...... ;
%include "&amp;amp;path/test.sas";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then the program "test.sas" that is called can assume that the macro variable PATH has already been set and use that to find the other programs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way is to change how your code is organized so that you can use AUTOCALL macros instead of %INCLUDING files with code in them. &amp;nbsp;Then you can just adjust the path used in the SASAUTOS option and SAS will find and automatically include the macro definition when you call your system macros. &amp;nbsp;Then your programsn look more like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%part1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include '../../part1.sas';
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jul 2016 01:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-relative-path-to-run-SAS-programs/m-p/283239#M57712</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-11T01:03:37Z</dc:date>
    </item>
  </channel>
</rss>

