Usage Note 24301: How to retrieve the program name that is currently running in batch mode or interactively
To retrieve the name of the current program when you are running SAS® in batch mode, you can issue the following statement:
%put The current program is %sysfunc(getoption(sysin));
If you are running SAS interactively, the following code retrieves the path and the name of the current program:
/* NOTE: If more than one editor window is open, then the STOP statement will need
to be commented out from the macro. SASHELP.VEXTFL creates a unique
fileref for each editor window that is open. Removing the STOP allows
us to retrieve the LAST file opened. */
%macro pname;
%global pgmname;
%let pgmname=;
data _null_;
set sashelp.vextfl;
if (substr(fileref,1,3)='_LN' or substr
(fileref,1,3)='#LN' or substr(fileref,1,3)='SYS') and
index(upcase(xpath),'.SAS')>0 then do;
call symput("pgmname",trim(xpath));
stop;
end;
run;
%mend pname;
%pname;
%put pgmname=&pgmname;
Beginning with SAS® 9, the above macro is not needed when using SAS in the Windows operating environment. There is a new environment variable for the Enhanced Editor named SAS_EXECFILENAME, and you can retrieve the current program by issuing this statement:
%put %sysget(SAS_EXECFILENAME);
There is also an environment variable for the Enhanced Editor named SAS_EXECFILEPATH that contains the full path of the submitted program or catalog entry. The full path includes the folder and the filename.
The environment variables SAS_EXECFILENAME and SAS_EXECFILEPATH are available only in the Windows operating environment running within the Enhanced Editor.
If you are using SAS® Enterprise Guide® or SAS® Studio, the macro variable _SASPROGRAMFILE can be used. This macro variable returns the full path and filename of the SAS program that is currently being run. This macro variable is available only for SAS program files that are saved on the same server on which your SAS Studio code or SAS Enterprise Guide session is running. For example:
Operating System and Release Information
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
Type: | Usage Note |
Priority: | low |
Topic: | SAS Reference ==> Macro
|
Date Modified: | 2012-01-04 10:40:02 |
Date Created: | 2005-06-17 15:47:05 |