Referencing External Files Indirectly

If you want to reference a file in only one place in a program so that you can easily change it for another job or a later run, you can reference a filename indirectly. Use a FILENAME statement, the FILENAME function, or an appropriate operating system command to assign a fileref or nickname, to a file.(footnote1) Note that you can assign a fileref to a SAS catalog that is an external file, or to an output device, as shown in the following table.
Referencing External Files Indirectly
External File Task
Tool
Example
Assign a fileref to a file that contains input data.
FILENAME
filename mydata 'input-file';
Assign a fileref to a file for output data.
FILENAME
filename myreport 'output-file';
Assign a fileref to a file that contains program statements.
FILENAME
filename mypgm 'source-file';
Assign a fileref to an output device.
FILENAME
filename myprinter <device-type> 
   <host-options>;
Specify the file that contains input data.
INFILE
data weight;
   infile mydata;
   input idno $ week1 week16;
   loss=week1-week16;
Specify the file that the PUT statement writes to.
FILE
file myreport;
if loss ge 5 and loss le 9 then
      put idno loss 'AWARD STATUS=3';
   else if loss ge 10 and loss le 14 then
      put idno loss 'AWARD STATUS=2';
   else if loss ge 15 then
      put idno loss 'AWARD STATUS=1';
run;
Bring statements or raw data from another file into your SAS job and execute them.
%INCLUDE
%include mypgm;
FOOTNOTE 1:In some operating environments, you can also use the command '&' to assign a fileref.[return]