Feb 8, 2013

Obtaining the Filename and Full Path of Submitted Programs

When you submit code or a catalog entry from the Enhanced Editor, the filename or catalog entry name and their respective folders are placed in these environment variables:
contains the full path of the submitted program or catalog entry. The full path includes the folder and the filename.
contains only the name of the submitted program or the catalog entry name.
You can then extract the filename and full path for use in your SAS programs.
After the following DATA step runs and the data is sorted, the PRINT procedure includes the filename in the title and the full path in the footnote of the procedure output. The results are shown below as a Screen Shot
data oranges;
   input variety $ flavor texture looks;
navel 9 8 6
temple 7 7 7
valencias 8 9 9
mandarins 5 7 9
proc sort data=oranges;
   by descending total;
proc print data=oranges;
title 'Taste Test Results for Oranges using File ' %sysget(SAS_EXECFILENAME);
footnote 'The full path is ' %sysget(SAS_EXECFILEPATH);
The resulting output displays the filename in the title and the full path in the footnote:
Using an Environment Variable to Place a Filename in DATA Step Output
These environment variables are set only when code is submitted using the Enhanced Editor in the Windows environment. They are not set when you submit SCL code or when you submit code in a batch session.
However, when SAS is running in batch mode, you can obtain the full path (which includes the filename) by submitting %sysfunc(getoption(SYSIN)) . The following macro can be used to obtain the full path in both a batch session and an interactive session by using the Enhanced Editor:
%let execpath=" ";
%macro setexecpath;
   %let execpath=%sysfunc(GetOption(SYSIN));
   %if %length(&execpath)=0
      %then %let execpath=%sysget(SAS_EXECFILEPATH);
%mend setexecpath;
%put &execpath;
You can also use the following %PUT macro statements to display the filename and full path in the SAS log:
%put Submitted file path is %sysget(SAS_EXECFILEPATH).;
%put Submitted file name is %sysget(SAS_EXECFILENAME).;

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.