|SAS Companion for the OS/390 Environment|
After you allocate an external file, you can read from the file in a SAS DATA step by specifying it in the INFILE statement, the INCLUDE command, or the %INCLUDE statement.
This section describes the INFILE statement. For information about the INCLUDE command, the %INCLUDE statement, and the DATA step, see SAS Language Reference: Dictionary.
In a SAS DATA step, the INFILE statement specifies which external file is to be read by a subsequent INPUT statement. Every external file that you want to read must have a corresponding INFILE statement. The external file can be a sequential data set on disk or tape, a member of a partitioned data set (PDS or PDSE), or any of several nonstandard file types (see the description of the type argument in INFILE Statement Syntax). The file can also be entered from a terminal.
The INFILE statement is executable. Therefore, it can be used in conditional processing--in an IF/THEN statement, for example.
When multiple INFILE statements are present, the INPUT
statement reads from the external file that was specified by the most recent
INFILE statement. (See SAS Language: Reference for a complete
description of the INPUT statement.)
This section provides a brief overview of INFILE statement syntax. For complete information about the INFILE statement, see INFILE.
The syntax of the INFILE statement is
|INFILE file-specification <type> <options>;|
See INFILE for information about partial physical filenames and wildcard member names.
|DLI||for IMS-DL/I databases. For information about IMS-DL/I options for the FILE statement, see SAS/ACCESS Interface to IMS-DL/I Software.|
|HFS and PIPE||for files in UNIX System Services (see Accessing UNIX System Services Files ). PIPE allows you to issue UNIX System Services commands from within the INFILE statement.|
|IDMS||specifies that the file is a CA-IDMS file. For information about CA-IDMS options for the INFILE statement, see SAS/ACCESS Interface to CA-IDMS Software: Reference.|
|ISAM||specifies that the file is an ISAM file. See Accessing Nonstandard Files.|
|VSAM||for VSAM files (see Accessing VSAM Data Sets ).|
|VTOC||specifies that the Volume Table of Contents (VTOC) is to be accessed.|
|Type of Data Set||Example|
|member of a PDS or PDSE||
|sequential or member of a PDS or PDSE*||
infile psb dli;
|*depending on what the fileref is associated with|
|Reading from a Sequential File|
This example assigns the fileref RAW to the data set MYID.RAW.DATAX and uses the fileref in a simple DATA step:
filename raw 'myid.raw.datax' disp=shr; data out; infile raw; input ... ; run;
This example is similar to the previous one, except that it specifies a value for the SYSPREF= system option and then uses a partially qualified data set name in the FILENAME statement:
options syspref=sys2.sas7; filename raw2 '.raw.datax' disp=shr; data out; infile raw2; input ... ; run;
See Specifying Physical Files for information about using SYSPREF= and partially qualified data set names.
|Reading from a Member of a PDS or PDSE|
This example specifies the PDS name in the FILENAME statement and then specifies the member name in parentheses following the fileref in the INFILE statement:
filename mypds 'user.my.pds'; data out; infile mypds(mydata); input ... ; run;
This example specifies both the PDS name and the member name in the FILENAME statement. Therefore, only the fileref is specified in the INFILE statement:
filename mymember 'user.my.pds(mydata)'; data out; infile mymember; input ... ; run;
Multiple members of a PDS can be open for read access at the same time.
|Reading from the Terminal|
If you run SAS in interactive line mode or in noninteractive mode, you can read input from the terminal. These examples illustrate ways to define a terminal file.
In the first example, TERMINAL is specified as the device type in the FILENAME statement:
filename term1 terminal; data one; infile term1; input ... ; run;
In the next example, an asterisk is used in place of an physical file name to indicate that the file will be entered from the terminal:
filename term2 '*'; data out; infile term2; input ... ; run;
Note: Enter "/*" to signify end-of-file
after entering your input from the terminal.
|Reading Concatenated Data Sets|
Multiple sequential data sets can be concatenated (via a JCL DD statement, a TSO ALLOCATE command, or a FILENAME statement) and read consecutively using one pair of INFILE/INPUT statements.
Sequential data sets and individual PDS or PDSE members can also be concatenated, as in the following example:
x alloc fi(in1) da('my.data1' 'my.pds(mem)' 'my.data2'); data mydata; infile in1; input ... ; /* SAS statements */ run;
Here is an example of using the FILENAME statement to concatenate data sets:
filename in1 ('my.data1' 'my.pds(mem)' 'my.data2');
You can also concatenate external files that are stored on different types of devices and that have different characteristics.
If PDSs or PDSEs are concatenated and a member is specified in the INFILE statement, then SAS searches each PDS or PDSE for that member. SAS searches in the order in which the PDSs appear in the DD statement, the ALLOCATE command, or the FILENAME statement or function. If the member is present in more than one of the PDSs, SAS retrieves the first one that it finds.
|Reading from Multiple External Files|
You can read from multiple external files either sequentially or alternately from multiple filerefs.
filename outrdr sysout=a pgm=intrdr recfm=fb lrecl=80; data _null_; length dsn $ 44; input dsn $; infile dummy filevar=dsn end=end; file outrdr noprint notitles; do until(end); input; put _infile_; end; cards; PROD.PAYROLL.JCL(BACKUP) PROD.PAYROLL.JCL(TRANS) PROD.PAYROLL.JCL(PRINT) ; run;
See SAS Language Reference: Dictionary for more information about the END= and EOF= options of the INFILE statement.
filename exfile1 'my.file.ex1'; filename exfile2 'my.file.ex2'; data mydata; infile exfile1; input ... ; /* SAS statements */ infile exfile2; input ... ; /* SAS statements */ infile exfile1; input ... ; /* SAS statements */ run;
When there is more than one INFILE statement for the same fileref, with options specified in each INFILE statement, the options apply cumulatively to successive files.
files inside concatenations cannot be accessed in this manner.
|Reading from Print Data Sets|
When reading from a print data set, you can tell SAS to ignore the carriage-control character that is in column 1 of print data sets by specifying the SAS system option FILECC. For more information, see FILECC.
|Getting Information about an Input Data Set|
In the following example, data set information is printed in the SAS log. Control blocks are printed in hexadecimal format. Note that only the first 100 bytes of the JFCB are printed. The example can be used with either a sequential data set or a PDS.
filename in 'user.data'; data out; infile in jfcb=jf dscb=ds volumes=vol ucbname=ucb devtype=dev; if (_n_ = 1) then put @1 'Data Set Name:' @17 jf $52. / @4 'Volume =' @20 vol $30. / @4 'JFCB =' @20 jf $hex200. / @4 'DSCB =' @20 ds $hex188. / @4 'Devtype =' @20 dev $hex48. / @4 'Device Addr =' @20 ucb $3. ; run;
Top of Page
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.