Previous Page | Next Page

Using External Files and Devices

Assigning a Fileref to a Directory (Using Aggregate Syntax)


Introduction to Aggregate Syntax

Aggregate syntax enables you to assign a fileref to a directory and then work with any file in that directory by specifying its filename in parentheses after the fileref.

FILENAME fileref directory-name;
Aggregate syntax is especially useful when you have to refer to several files in one directory.

Example 1: Referring to a File Using Aggregate Syntax

To refer to a file in the directory, specify the fileref followed by the individual filename in parentheses. For example, you can refer to the file cars.dat in the directory /users/pat as shown in this example:

filename prices '/users/pat';
data current.list;
   file prices(cars);
   ...other SAS statements...
run;


Example 2: Using Aggregate Syntax with Filerefs Defined by Environment Variables

You can also use aggregate syntax with filerefs that have been defined using environment variables. (See Using Environment Variables to Assign Filerefs in UNIX Environments.) For example:

x setenv PRICES /users/pat;
data current.list;
   file prices(cars);
   ...other SAS statements...
run;


Assigning a Fileref to Several Directories

In the FILENAME statement, you can concatenate directory names and use the fileref to refer to any file within those directories:

FILENAME fileref ("directory-1" ... "directory-n");
When you concatenate directory names, you can use aggregate syntax to refer to a file in one of the directories. For example, assume that the Report.sas file resides in the directory associated with the MYPROGS environment variable. When SAS executes the following code, it searches for Report.sas in the pathnames that are specified in the FILENAME statement and it executes the program.
filename progs ("$MYPROGS" "/users/mkt/progs");
%inc progs(report);

SAS searches the pathnames in the order specified in the FILENAME statement until

Previous Page | Next Page | Top of Page