Chapter Contents


SAS Companion for UNIX Environments

Specifying Pathnames

You can reference an external file directly by specifying its pathname in the FILE, INFILE, or %INCLUDE statements, or you can reference the file indirectly by specifying a fileref and a pathname in the FILENAME statement and then using the fileref in the FILE, INFILE, or %INCLUDE statements.

Whether you reference a file directly or indirectly, you will need to specify its pathname in the appropriate statement. In most cases, you must enclose the name in quotes. For example, the following INFILE statement refers to the file /users/pat/cars:

infile '/users/pat/cars';
The following FILE statement directs output to the specified terminal:
file '/dev/ttyp1';

The level of specification depends on your current directory. You can use the character substitutions shown in Character Substitutions in Pathnames to specify the pathname. You can also use wildcards as described in Using Wildcards in Pathnames (Input Only).

You can omit the quotes on a filename if

For example, if the current directory is /users/mkt/report and it includes file, you can reference in any of the following statements:

%include '/users/mkt/report/';
%include '';
file '';
If there is no QTR fileref already defined, you can omit the quotes and the filename extension on the %INCLUDE statement:
%include qtr;

Using Wildcards in Pathnames (Input Only)

You can use the *, ?, and [ ] wildcards to specify pathnames in the FILENAME (only if the fileref is to be used for input), INFILE, and %INCLUDE statements and the INCLUDE command.
* matches one or more characters, except for the period at the beginning of filenames.
? matches any single character.
[ ] matches any single character from the set of characters defined within the brackets. You can specify a range of characters by specifying the starting character and ending character separated by a hyphen.
Wildcards are supported for input only. You cannot use wildcards in the FILE statement.

The following example reads input from every file in the current directory that begins with the string wild and ends with .dat:

filename wild 'wild*.dat';
   infile wild;

The following example reads input from every file in every subdirectory of the current working directory:

filename subfiles '*/*';
   infile subfiles;
If new files are added to any of the subdirectories, they can be accessed with the subfiles fileref without changing the FILENAME statement.

You can also use wildcards in filenames, but not in directory names, when you use aggregate syntax:

filename curdir ".";
  infile curdir('wild*');
The period in the FILENAME statement refers to the current directory. See Character Substitutions in Pathnames for information on other characters substitutions available on UNIX.

The following statement associates the fileref myref with all files that begin with alphabetic characters. Files beginning with numbers or other characters such as the period or tilde are excluded.

filename myref '[a-zA-Z]*.dat';
The following statement associates myref with any file beginning with sales (in either uppercase, lowercase, or mixed case) and a year between 1990 and 1999:
filename myref '[Ss][Aa][Ll][Ee][Ss]199[0-9].dat';

Chapter Contents



Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.