Chapter Contents |
Previous |
Next |
SAS Companion for the OpenVMS Operating Environment |
Order of Precedence for External File Specifications |
Assigning Filerefs |
Assigning OpenVMS Logical Names to External Files |
When you assign an OpenVMS logical name to an external file, you cannot use the pound sign (#) or the at sign (@) because these characters are not valid in OpenVMS logical names. (By contrast, if you use the FILENAME statement to assign a fileref, you can use these characters because filerefs follow SAS naming conventions.) Also, using the DCL DEFINE command to define an OpenVMS logical name does not allow you to specify the keywords or options that are available with the FILENAME statement and the FILENAME function.
Remember that you can use the SAS X statement or X command to issue a DCL DEFINE command from within a SAS program or a SAS process. (For details, see Issuing DCL Commands during a SAS Session.)
Note: If you use the SAS X statement or X command to
issue the DCL DEFINE command, then you want to use the method described in Using the X Statement to Issue a Single DCL Command
(which executes the command in the parent OpenVMS process),
not the method described in Using the X Statement to Issue Several DCL Commands (which executes multiple DCL
commands in an OpenVMS subprocess). OpenVMS logical
names that are defined in a subprocess are not recognized by the current SAS
process. By contrast, OpenVMS logical
names that are defined in the OpenVMS parent
process are available for use during the current SAS process.
Suppose you want to read a data file named [YOURDIR]EDUC.DAT, and you decide to use an OpenVMS logical name to access the file. You can issue the DCL DEFINE command before you invoke the SAS System. The following is an example:
$ DEFINE INED [YOURDIR]EDUC.DAT
Alternatively, you can use the SAS X statement to issue a DCL DEFINE command in your SAS program:
x 'define ined [yourdir]educ.dat';
Either of these methods properly associates the OpenVMS logical name INED with the file [YOURDIR]EDUC.DAT. You can then use INED as the file specification in the INFILE statement:
infile ined;
You can use the same methods to write to an external file. For example, use an X statement to issue a DCL DEFINE command as follows:
x 'define outfile [yourdir]scores.dat';
Then use the OpenVMS logical name OUTFILE as the file specification in the following FILE statement:
file outfile;
Using OpenVMS Pathnames to Identify External Files |
Here are some examples of valid file specifications:
infile 'node2::device:[dir1.subdir1]food.dat'; file '[mydir]prices.dat';
To access a particular version of a file, include the version number in the quoted file specification. If you omit the version number, then SAS uses the most recent version when reading, and it creates a new version when writing. To append records to the end of an existing file, use the MOD option in the FILE statement, type APPEND in windowing environment filename fields, or use the FAPPEND function. For example, the following FILE statement appends data lines to the file PRICES.DAT;1:
file 'prices.dat;1' mod;
The following are some examples of valid uses of wildcard characters:
filename myfile '*.data';
%include '*.sas';
infile 'test%.dat';
infile '[data...]*.test_data';
The special characters # (pound sign) and @ (at sign)
cannot be used in external file specification because they are not valid in OpenVMS filenames.
The usual rules for OpenVMS version-numbering apply. You cannot use a percent symbol (%) in the version number field.
The following are some examples of valid concatenation specifications:
filename allsas 'one.sas, two.sas, three.sas';
filename alldata 'test.data1, test.data2,
test.data3';
%include 'one.sas, two.sas';
infile '[area1]alldata.dat,[area2]alldata.dat';
infile
'test*.dat, in.dat';
Using Aggregate Syntax to Identify External Files |
filename myfile '[mydir]';
To access a file named SCORES02.DAT in that directory, you could use the following INFILE statement:
infile myfile(scores02);
By default, the INFILE statement appends a file type of .DAT to the SCORES02 filename if a filetype is not specified. (For more information about default file types, see Default File Types.)
If you want to specify a different file type, then enclose the file specification in quotation marks, as in the following example:
infile myfile('scores02.new');
Aggregate syntax is also used to identify OpenVMS text libraries. An OpenVMS text library has a default file type of .TLB and can store frequently used text files. For example, if you have several related files of data, you may want to store them in one OpenVMS text library. OpenVMS text libraries are also commonly used as SAS autocall libraries, which store SAS macros. For more information, see Autocall Libraries.
To access a file in an OpenVMS text library, first assign a fileref or OpenVMS logical name to the text library. Then, in an INFILE or FILE statement, specify the fileref or logical name, followed by the filename in parentheses.
For example, you can use the following FILENAME statement to assign a fileref to an OpenVMS text-library:
filename mytxtlib '[mydir]mydata.tlb';
Then, assuming that you want to use a library member named SCORES01, you can use the following INFILE statement:
infile mytxtlib(scores01);
Note: The file-type rules for OpenVMS text library syntax differ from the rules for directory-based aggregate syntax. When referring to a member of an OpenVMS text library, do not specify a file type. If you do, the file type is ignored. For example, in the following statements the fileref TEST refers to an OpenVMS text library:
filename test 'mylib.tlb'; data _null_; file test(one.dat); put 'first'; run;
The file type .DAT is ignored, and the FILE statement
writes member ONE to the text library, not to ONE.DAT. Wildcard
characters are not allowed in filenames when you are using OpenVMS text-library
syntax.
Identifying an External File That Is in Your Default Directory |
As explained in Order of Precedence for External File Specifications, if an external file specification is a valid SAS name and is neither quoted nor a previously defined fileref or OpenVMS logical name, then SAS opens a file by that name in your default directory. Therefore, you cannot use the special characters # or @ in the external file specification, because these characters are not valid in OpenVMS filenames.
The specification must be a filename only; do not include the file type. The SAS System uses a default file type depending on whether you are reading or writing data lines or reading SAS statements, as indicated in Default File Types.
The following INFILE statement reads the data file FOOD.DAT from the default directory (FOOD has not been defined as a SAS fileref nor as an OpenVMS logical name):
infile food;When SAS encounters this statement, it searches the default directory for a file named FOOD.DAT. Records are read from FOOD.DAT according to subsequent INPUT statement specifications.
The following FILE statement writes data lines to the file PRICES.DAT in the default directory (PRICES has not been defined as a SAS fileref nor as an OpenVMS logical name):
file prices;When SAS encounters this statement, it writes to a file named PRICES.DAT in the default directory. Data lines are written to PRICES.DAT according to subsequent PUT statement specifications.
The default file types are different if you are using windowing environment commands. Default File Types for Commands and Statements lists the default file types for SAS statements and commands. Be sure to include the file type in a quoted file specification unless you are sure that the SAS System default is correct.
Reference | File Type | Window | |
---|---|---|---|
FILE command | .SAS | Program Editor | |
FILE command | .LOG | Log | |
FILE command | .LIS | Output | |
INCLUDE command | .SAS | Program Editor | |
FILE statement | .DAT | Program Editor | |
%INCLUDE statement | .SAS | Program Editor | |
INFILE statement | .DAT | Program Editor |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.