Rhea
Rhea

Reputation: 293

Get the filename and filepath of the code running

I need to get the current running SAS program's name and file path into local variables. I accomplished that using the SAS_EXECFILEPATH and SAS_EXECFILEPATH commands. I ran this through windows SAS and it worked.

But when i tried to run this on the server in batch mode, it failed. I then tried the &_SASPROGRAMFILE parameter, which ran fine on SAS EG, but fails when I trigger it on the server in batch mode.

Is there a possible way to accomplish this in batch mode on the server?

Upvotes: 4

Views: 6008

Answers (2)

Charity del Sol
Charity del Sol

Reputation: 1

I know this is delayed but you could generate a macro that calls on the right code depending on if you are running the program in the editor or in batch mode. Art Carpenter created a great macro that solves this issue.

%macro ExecPrg;

%if %sysfunc(getoption(sysin)) ne %str() %then %do;
  /* Batch Execution */
%sysfunc(getoption(sysin))
%end;
%else %do;
  /* Interactive Execution */
  %sysget(SAS_EXECFILEPATH)
%end;
%mend execprg;

Upvotes: 0

Nickolay
Nickolay

Reputation: 32073

You might be looking for %sysfunc(getoption(sysin)) (Usage Note 24301: How to retrieve the program name that is currently running in batch mode or interactively), if you start the program with sas -sysin path/to/file.sas.

Upvotes: 3

Related Questions