You can assign
a fileref to a directory and then access individual files within that
directory using member-name syntax (also called aggregate syntax).
For example, if all
your regional sales data for January are stored in the directory
C:\SAS\MYDATA
, you can issue the following FILENAME
statement to assign the fileref JAN to this directory:
filename jan "c:\sas\mydata";
Now you can use this
fileref with a member name in your SAS programs. In the following
example, you reference two files stored in the JAN directory:
data westsale;
infile jan(west);
input name $ 1-16 sales 18-25
comiss 27-34;
run;
data eastsale;
infile jan(east);
input name $ 1-16 sales 18-25
comiss 27-34;
run;
When you use member-name
syntax, you do not have to specify the file extension for the file
that you are referencing, as long as the file extension is the expected
one. For example, in the previous example, the INFILE statement expects
a file extension of .DAT. The following table lists the expected file
extensions for the various SAS statements and commands:
Default File Extensions for Referencing External Files with
Member-Name Syntax
For example, the following
program submits the file
C:\PROGRAMS\TESTPGM.SAS
to SAS:
filename test "c:\programs";
%include test(testpgm);
SAS searches for a filename
TESTPGM.SAS in the directory C:\PROGRAMS.
If your file has a file
extension different from the default file extension, you can use the
file extension in the filename, as in the following example:
filename test "c:\programs";
%include test(testpgm.xyz);
If your file has no
file extension, you must enclose the filename in quotation marks,
as in the following example:
filename test "c:\programs";
%include test("testpgm");
To further illustrate
the default file extensions SAS uses, here are some more examples
using member-name syntax. Assume that the following FILENAME statement
has been submitted:
filename test "c:\mysasdir";
The following example
opens the file
C:\MYSASDIR\PGM1.DAT
for output:
file test(pgm1);
The following example
opens the file
C:\MYSASDIR\PGM1.DAT
for input:
infile test(pgm1);
The following example
reads and submits the file
C:\MYSASDIR\PGM1:
%include test("pgm1");
Another feature of member-name
syntax is that it enables you to reference a subdirectory in the working
directory without using a fileref. For example, suppose you have
a subdirectory named PROGRAMS that is located beneath the working
directory. You can use the subdirectory name PROGRAMS when referencing
files within this directory. For example, the following statement
submits the program stored in
working-directory \PROGRAMS\PGM1.SAS:
%include programs(pgm1);
The next example uses
the FILE command to save the contents of the active window to
working-directory \PROGRAMS\TESTPGM.DAT:
file programs(testpgm);
Note: If a directory name is the
same as a previously defined fileref, the fileref takes precedence
over the directory name.