Obtaining the Filename and Full Path of Submitted Programs

  • Follow


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:

SAS_EXECFILEPATH
contains the full path of the submitted program or catalog entry. The
full path includes the folder and the filename.

SAS_EXECFILENAME
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;
   total=flavor+texture+looks;
cards;
navel 9 8 6
temple 7 7 7
valencias 8 9 9
mandarins 5 7 9
;

proc sort data=oranges;
   by descending total;
run;

proc print data=oranges;
title 'Taste Test Results for Oranges using File ' %sysget
(SAS_EXECFILENAME);
footnote 'The full path is ' %sysget(SAS_EXECFILEPATH);
run;

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;

%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).;

Source: http://support.sas.com/onlinedoc/913/getDoc/en/hostwin.hlp/editor_enhanced.htm#eegetfilename
Read more @ http://sastechies.blogspot.com/2009/12/obtaining-filename-and-full-path-of.html
0
Reply sastechiesblog (4) 12/2/2009 4:49:32 PM


0 Replies
269 Views

(page loaded in 1.363 seconds)

Similiar Articles:













7/17/2012 12:54:42 AM


Reply: