Using Environment Variables to Assign Filerefs in UNIX Environments


Requirements for Variable Names

An environment variable can also be used as a fileref to refer to DISK files. The variable name must be in all uppercase characters , and the variable value must be the full pathname of the external file; that is, the filename must begin with a slash.

Note  

If a variable and a fileref have the same name but refer to different files, SAS uses the fileref. For example, the %INCLUDE statement below refers to file /users/ myid/this_one .

 filename ABC '/users/myid/this_one';   x setenv ABC /users/myid/that_one;   %include ABC; 

Reading a Data File

Suppose that you want to read the data file /users/myid/educ.dat , but you want to refer to it with the INED environment variable. You can define the variable at two times:

  • before you invoke SAS. See "Defining Environment Variables in UNIX Environments" on page 21. For example, in the Korn shell, you use

     export INED=/users/myid/educ.dat 
  • after you invoke SAS by using the X statement (see "Executing Operating System Commands from Your SAS Session" on page 13) and the SAS setenv command:

     x setenv INED /users/myid/educ.dat; 

After INED is associated with the file /users/myid/educ.dat , you can use INED as a fileref to refer to the file in the INFILE statement:

 infile ined; 

Writing to an External File

The same method applies if you want to write to an external file. For example, you can define OUTFILE before you invoke SAS:

 OUTFILE=/users/myid/scores.dat   export OUTFILE 

Then, use the environment variable name as a fileref to refer to the file:

 file outfile; 



SAS 9.1 Companion for UNIX Environments
SAS 9.1 Companion For Unix Enivronments
ISBN: 1590472101
EAN: 2147483647
Year: 2004
Pages: 185
Authors: SAS Institute

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net