<?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: Global Macro Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/809776#M319336</link>
    <description>&lt;P&gt;Late reply but here we go. Hopefully this helps someone in the future :&lt;/P&gt;
&lt;P&gt;SAS Windows environment maintains the SAS OPTION of SAS_EXECFILEPATH as the location of the SAS file that you are running.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS EG keeps the file path and program name logged in its systems macro variables. The path would be housed in &amp;amp;_SASPROGRAMFILE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To assign these values in a macro variable you could do :&lt;/P&gt;
&lt;P&gt;1. %let New_path=&lt;U&gt;%sysfunc(dequote(&amp;amp;_SASPROGRAMFILE))&lt;/U&gt;; /*----Enterprise Guide-----*/&lt;/P&gt;
&lt;P&gt;2. %let New_path=&lt;U&gt;%sysget(SAS_EXECFILEPATH)&lt;/U&gt;; /*----SAS Windows Environment-----*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bonus: If you run SAS is batch mode using a BAT. file to open SAS and call the program you want,&amp;nbsp; the input changes to SYSIN when you use the window CMD language "sysin" to call the file&amp;nbsp; :&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp;%let New_path=&lt;U&gt;%sysfunc(getoption(SYSIN));&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Apr 2022 21:05:38 GMT</pubDate>
    <dc:creator>GreyJoy</dc:creator>
    <dc:date>2022-04-25T21:05:38Z</dc:date>
    <item>
      <title>Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283884#M57888</link>
      <description>&lt;P&gt;Hi All - I am looking for a global macro variable which should be able to detect my current program path. I would like to add this to my autoexec file and call the macro in the SAS&amp;nbsp;program. Can someone please help me?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 20:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283884#M57888</guid>
      <dc:creator>KBACHU</dc:creator>
      <dc:date>2016-07-12T20:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283887#M57889</link>
      <description>&lt;P&gt;%global variable_name;&lt;/P&gt;&lt;P&gt;%let variable_name = path;&lt;/P&gt;&lt;P&gt;save this in the autoexec file. You would be able to use the macro variable in the sas code that will resolve to the path.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 20:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283887#M57889</guid>
      <dc:creator>PBsas</dc:creator>
      <dc:date>2016-07-12T20:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283888#M57890</link>
      <description>&lt;P&gt;Something like this perhaps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let workpath=%sysfunc(pathname(work));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At startup Base&amp;nbsp;SAS usually defaults to the work library location.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 21:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283888#M57890</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-12T21:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283889#M57891</link>
      <description>&lt;P&gt;Thanks for your response, but this way I have to define many macro variables in the autoexec file. I am looking for something which should be able to detect the program path and I want to use this in many other SAS programs. Is there any option in SAS which will be able to detect the current program path?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 21:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283889#M57891</guid>
      <dc:creator>KBACHU</dc:creator>
      <dc:date>2016-07-12T21:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283890#M57892</link>
      <description>&lt;P&gt;The reason I am looking for this option is because I can use relative path to call other SAS programs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%include '&amp;amp;currentpath\..\..test.sas';&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 21:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283890#M57892</guid>
      <dc:creator>KBACHU</dc:creator>
      <dc:date>2016-07-12T21:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283892#M57893</link>
      <description>&lt;P&gt;You may use SYSPROCESSNAME.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 21:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283892#M57893</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-07-12T21:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283893#M57894</link>
      <description>You will have to parse out the value. &lt;BR /&gt;&lt;BR /&gt;If I run &lt;BR /&gt;&lt;BR /&gt;sas /home/jan/test.sas&lt;BR /&gt;&lt;BR /&gt;then I get &lt;BR /&gt;&lt;BR /&gt;SYSPROCESSNAME=Program /home/jan/test.sas&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Jul 2016 21:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283893#M57894</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-07-12T21:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283916#M57897</link>
      <description>&lt;P&gt;You may be looking for the SAS environment variable SAS_EXECFILEPATH if you are looking for the location of the sas code file.&lt;/P&gt;
&lt;P&gt;You would get to that using %sysget(SAS_EXECFILEPATH) this returns the path AND the program file name. It assumes the program file has been saved before the %sysget() is executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This could be in any code file it need not be in the autoexec.sas (in fact you wouldn't want it as it there&amp;nbsp;would have the location of the autoexec!)&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 23:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283916#M57897</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-12T23:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283927#M57903</link>
      <description>&lt;P&gt;What do you mean by "current program"? How did you submit the program.&lt;/P&gt;
&lt;P&gt;If you issued started SAS from the command line then the SYSIN option should have the name of the program you are running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise is is very difficult for SAS to know how you submitted the program. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some have suggested using the environment variable (&lt;SPAN&gt;SAS_EXECFILEPATH) that the enhanced program editor sets. &amp;nbsp;That might work some times IF&amp;nbsp;you are using PC-SAS and IF&amp;nbsp;you are using the enhanced program editor (instead of the many other ways to edit and/or submit SAS code in PC-SAS) and IF you happened to save the program before submitting it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 00:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/283927#M57903</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-13T00:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/284165#M57968</link>
      <description>&lt;P&gt;Current program refers to the program which I am executing in SAS EG interface.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am submitting the program from SAS EG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using the below code to get the sas program path, but this works only from DMS SAS, and does not work from SAS EG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro pathfind;&lt;BR /&gt;%sysget(SAS_EXECFILEPATH)&lt;BR /&gt;%mend pathfind;&lt;BR /&gt;%put %pathfind;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From SAS EG, I get the below warning message,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WARNING: The argument to macro function %SYSGET is not defined as a system variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 18:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/284165#M57968</guid>
      <dc:creator>KBACHU</dc:creator>
      <dc:date>2016-07-13T18:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/284171#M57969</link>
      <description>&lt;P&gt;SAS_EXECFILEPATH is an environment variable set on your PC by the Enhanced Editor in PC-SAS. &amp;nbsp;Not surprisingly it will not be set if you submit your program from Enterprise Guide.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could submit a simple program to look at all macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put _ALL_;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And environment variables (if you are allowed to use PIPEs).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set 'env' pipe;
  input;
  put _infile_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And looks around and see if Enterprise Guide has left any bread&amp;nbsp;crumbs you can follow home.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But since your Enterprise Guide projects live on your PC and not on the server where SAS is running. &amp;nbsp;Also also since the SAS programs live inside the project and not as .sas files on the file system I really doubt you will find any crumbs that the birds have not already eaten.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 19:02:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/284171#M57969</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-13T19:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/284176#M57971</link>
      <description>&lt;P&gt;Thank You Tom. Looks like, there is no way I can get the program path name from SAS EG. I will look for other options.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 19:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/284176#M57971</guid>
      <dc:creator>KBACHU</dc:creator>
      <dc:date>2016-07-13T19:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/285244#M58268</link>
      <description>&lt;P&gt;Hi All - I found a sasnote which says that I can use _SASPROGRAMFILE from SAS EG/Studio to retrieve the filename/path. I am using the below statmenet&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put %sysget(_SASPROGRAMFILE);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but getting the message saying that as below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;WARNING: The argument to macro function %SYSGET is not defined as a system variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do I need to define %sysget as a system variable? I am connecting to a SAS server running on windows OS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/301.html" target="_blank"&gt;http://support.sas.com/kb/24/301.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2016 14:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/285244#M58268</guid>
      <dc:creator>KBACHU</dc:creator>
      <dc:date>2016-07-18T14:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/809776#M319336</link>
      <description>&lt;P&gt;Late reply but here we go. Hopefully this helps someone in the future :&lt;/P&gt;
&lt;P&gt;SAS Windows environment maintains the SAS OPTION of SAS_EXECFILEPATH as the location of the SAS file that you are running.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS EG keeps the file path and program name logged in its systems macro variables. The path would be housed in &amp;amp;_SASPROGRAMFILE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To assign these values in a macro variable you could do :&lt;/P&gt;
&lt;P&gt;1. %let New_path=&lt;U&gt;%sysfunc(dequote(&amp;amp;_SASPROGRAMFILE))&lt;/U&gt;; /*----Enterprise Guide-----*/&lt;/P&gt;
&lt;P&gt;2. %let New_path=&lt;U&gt;%sysget(SAS_EXECFILEPATH)&lt;/U&gt;; /*----SAS Windows Environment-----*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bonus: If you run SAS is batch mode using a BAT. file to open SAS and call the program you want,&amp;nbsp; the input changes to SYSIN when you use the window CMD language "sysin" to call the file&amp;nbsp; :&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp;%let New_path=&lt;U&gt;%sysfunc(getoption(SYSIN));&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 21:05:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/809776#M319336</guid>
      <dc:creator>GreyJoy</dc:creator>
      <dc:date>2022-04-25T21:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/809781#M319341</link>
      <description>&lt;P&gt;Note that the SAS_EXECFILEPATH environment variable is not really very reliable.&lt;/P&gt;
&lt;P&gt;It only works in the "enhanced" editor, not the normal Display Manager program editor window that works in all versions of SAS.&amp;nbsp; And then it only knows what name you last used for the file.&amp;nbsp; You might not have ever saved the file.&amp;nbsp; You might have modified that file and not saved the changes.&lt;/P&gt;
&lt;PRE&gt;7     * Regular program editor ;
8     %put SAS_EXECFILE=%sysget(SAS_EXECFILEPATH);
SAS_EXECFILE=
9     * Enhanced editor, file saved ;
10    %put SAS_EXECFILEPATH=%sysget(SAS_EXECFILEPATH);
SAS_EXECFILEPATH=C:\downloads\test1.sas
11    * Enhanced editor, file not save yet ;
12    %put SAS_EXECFILEPATH=%sysget(SAS_EXECFILEPATH);
SAS_EXECFILEPATH=
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 21:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Variable/m-p/809781#M319341</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-25T21:49:31Z</dc:date>
    </item>
  </channel>
</rss>

