Chapter Contents


SAS Companion for the OS/390 Environment

Reading from External Files

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.

INFILE Statement

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.)

INFILE Statement Syntax

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>;

identifies the file. It may be in the following forms:

Form Example
reserved fileref

See INFILE for information about partial physical filenames and wildcard member names.

specifies the type of file. When you omit type, the default is a standard external file. Nonstandard (host-specific) file types that you can specify for OS/390 are
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.

describe the input file's characteristics and specify how it is to be read with an INPUT statement. Many of these options are not host-dependent and are documented in SAS Language Reference: Dictionary. Those that are host-specific are documented in INFILE. You can use these options to do the following:

INFILE Statement Examples

File Specification Examples for the INFILE Statement
Type of Data Set Example
infile '';
member of a PDS or PDSE
infile report(feb);


infile 'lib.daily.src(rpt1)';
sequential or member of a PDS or PDSE*
infile data;
infile psb dli;
infile datalines;
*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 ... ;

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 ... ;

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 '';
data out;
   infile mypds(mydata);
   input ... ;

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 '';
data out;
   infile mymember;
   input ... ;

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 ... ;

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 ... ;

Note:   Enter "/*" to signify end-of-file after entering your input from the terminal.  [cautionend]

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  */

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.

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 '';
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.      ;

Chapter Contents



Top of Page

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