The macro in the Program section below is not needed when using SAS in the Windows
operating environment. There is a new environment variable for the Enhanced Editor
named SAS_EXECFILENAME. 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.
Program
%macro pname;
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 symputx('pgmname',xpath,'g');
stop;
end;
run;
%mend pname;
%pname
%put pgmname=&pgmname;
Program Description
Begin the macro definition.
%macro pname;
Begin a DATA step and reference the path information for external files (filerefs) by
using the SET statement and accessing the SASHELP.VEXTFL view.
data _null_;
set sashelp.vextfl;
Conditionally check each fileref to see whether the first three characters are _LN or #LN
or SYS and that the XPATH variable contains a .SAS extension. These are the possible
prefixes of the current executing program.
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;
If the condition above is true, then place the contents of the XPATH variable (the
program name) into a macro variable named &PGMNAME using the CALL SYMPUTX
call routine. The third argument of 'g' makes the macro variable &PGMNAME global.
Then stop the DATA step.
call symputx('pgmname',xpath,'g');
stop;
Example 6: How to Retrieve the Program Name That Is Currently Running in Batch Mode
or Interactively 457