Usage Note 24301: How can I retrieve the program name that is currently running in batch or interactively?
If you are running in batch, then you can issue the following statement to retrieve the name of the current program:
%put The current program is %sysfunc(getoption(sysin));
If you are running interactively, then the following code retrieves the path and the name of the current program:
/* NOTE: If more than one editor window is open 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. 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.
Operating System and Release Information
| Product Family | Product | System | Reported Release | Fixed Release* |
| SAS System | Base SAS | All | n/a | |
*
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: | 2007-12-04 13:20:56 |
| Date Created: | 2005-06-17 15:47:05 |