Ways of Allocating External Files

Overview of Allocating External Files

To work with an external file in SAS software, you must first allocate the file. File allocation is the process of identifying an external file to SAS software. If you are allocating a new data set, such as a sequential file, partitioned data set (PDS), or partitioned data set extended (PDSE), you must specify that it is new. You must also describe its structure and format. These actions are not required for new files in the UNIX System Services (USS) file system.
The method that you use to allocate an external file depends on whether you plan to use the file more than once in your SAS program. For more information, see Allocating a File for a Single Use and Allocating a File for Multiple Uses.

Allocating a File for a Single Use

If you plan to use an existing external file only once in your SAS program, then you can allocate it by specifying the physical filename in a SAS statement or command. For example, this INCLUDE command allocates an existing sequential data set and includes it into the PROGRAM EDITOR window:
include 'myid.report.data'
Similarly, this PROC PRINTTO statement allocates a new PDS member:
proc printto print='userid.output.data(rockport)' new;

Allocating a File for Multiple Uses

If you plan to use the same external file several times in your SAS program, then use one of the following methods to allocate the file:
SAS FILENAME statement or function
You can use these methods in all modes for most types of files. For more information, see Using the FILENAME Statement or Function to Allocate External Files or FILENAME Function: z/OS.
JCL DD statement
You can use this method if you use z/OS in batch mode. For more information, see Using the JCL DD Statement to Allocate External Files.
Note: Unlike the other two methods, if you use the JCL DD statement to allocate a file, there is no way to deallocate the file until the job ends.
TSO ALLOCATE command
You can use this method if you use TSO under z/OS. For more information, see Using the TSO Allocate Command to Allocate External Files.
Each of these methods establishes a fileref or a ddname that you can subsequently use to refer to the file instead of specifying the data set name again. For more information, see Referring to External Files.