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" on page 139). 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

  • it finds the first file with the specified name. Even if you use wildcards (see "Using Wildcards in Pathnames (Input Only)" on page 134) in the filename, SAS matches only one file.

  • it encounters a filename in the list of pathnames that you specified in the FILENAME statement.




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