Search code examples
sasenterprise-guide

Determine the folder of a SAS source file


When I open a SAS file in enterprise guide and run it, it is executed on the server. The source file itself is located either on the production site or the development site. In both cases, it is executed the same server however. I want to be able to tell my script to store results in a relative folder. But if I write something like

libname lib_out xport "..\tmp\foobar.xpt";

I get an error, because the working folder of the SAS Enterprise Guide process is not the location of my source file, but a folder on the server. And the folder ..\tmp does not exist there. Even if it would, the server process does not have write permission in that folder.

I would like to determine from which folder the .sas file was loaded and set the working folder accordingly. In one case it's S:\Development\myproject\sas\foobar.sas and in the other case it's S:\Production\myproject\sas\foobar.sas

It this possible at all? Or how would you do this?


Solution

  • Depending on the way EG is configured, you may be able to use something like the syshostname global macro variable to determine where to save your results:

    %macro sasdir;
        %global sasdir;
        %if "&syshostname" eq "mydevelopmenthost" %then %do;
          %let sasdir = S:\Development;
        %end;
        %else %if "&syshostname" eq "myproductionhost" %then %do;
          %let sasdir = S:\Production;
        %end;
    %mend;
    %sasdir;
    
    libname lib_out xport "&sasdir\myproject\sas\tmp\foobar.xpt";
    

    If not, try looking at what other global or automatic macro variables may be able to help you by doing a:

    %put _all_; 
    

    Hope this helps

    Cheers Rob