views:

75

answers:

2

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?

A: 

OK, this isn't going to answer your question exactly, but I have this macro easily available so I thought I would share it. From here you would just need to do a little string processing.

%macro progName;
%* Returns the name of current program;
    %let progPath = %sysfunc(GetOption(SysIn));
    %* if running in interactive mode, the above line will not work, and the next line should;
    %if  %length(&progPath) = 0 %then %let progPath = %sysget(SAS_ExecFilePath);

    %str(&progPath)
%mend progName;
Louisa Grey
+1  A: 

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

Rob Penridge
thanks. This is usable. Not perfect, but good enough. Annoyingly enough, it turned out that the script containing this code is to be replaced with an SPSS script in which I have the exact same problem... :| And I haven't figured out yet how to get the client machine name in SPSS...
exhuma
Good to hear. Yeah it's kinda tough to give you exactly what you need without knowing all your environment details. There's lots of ways to skin this cat but that's a relatively simple one. Can't help with the SPSS sorry!
Rob Penridge