SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3

SASFILE Statement

Opens a SAS data set and allocates enough buffers to hold the entire file in memory

Valid: Anywhere

Category: Program Control

Restriction: A SAS data set opened by the SASFILE statement can be used for subsequent input (read) or update processing but not for output or utility processing.

See: SASFILE Statement in the documentation for your operating environment.

Syntax

SASFILE < libref .> member- name <. member-type ><( password-option(s) )> OPEN LOAD CLOSE ;

Arguments

libref

member-name

member-type

password-option(s)

OPEN

LOAD

CLOSE

Details

General Information The SASFILE statement opens a SAS data set and allocates enough buffers to hold the entire file in memory. Once it is read, data is held in memory, available to subsequent DATA and PROC steps or applications, until either a second SASFILE statement closes the file and frees the buffers or the program ends, which automatically closes the file and frees the buffers.

Using the SASFILE statement can improve performance by

If your SAS program consists of steps that read a SAS data set multiple times and you have an adequate amount of memory so that the entire file can be held in real memory, the program should benefit from using the SASFILE statement. Also, SASFILE is especially useful as part of a program that starts a SAS server such as a SAS/SHARE server. However, as with most performance-improvement features, it is suggested that you set up a test in your environment to measure performance with and without the SASFILE statement.

Processing a SAS Data Set Opened with SASFILE When the SASFILE statement executes, SAS opens the specified file. Then when subsequent DATA and PROC steps execute, SAS does not have to open the file for each request; the file remains open until a second SASFILE statement closes it or the program or session ends.

When a SAS data set is opened by the SASFILE statement, the file is opened for input processing and can be used for subsequent input or update processing. However, the file cannot be used for subsequent utility or output processing, because utility and output processing requires exclusive access to the file (member-level locking). For example, you cannot replace the file or rename its variables .

Table 7.10 on page 1391 provides a list of some SAS procedures and statements and specifies whether they are allowed if the file is opened by the SASFILE statement:

Table 7.10: Processing Requests for a File Opened by SASFILE

Processing Request

Open Mode

Allowed

APPEND procedure

update

Yes

DATA step that creates or replaces the file

output

No

DATASETS procedure to rename or add a variable, add or change a label, or add or remove integrity constraints or indexes

utility

No

DATASETS procedure with AGE, CHANGE, or DELETE statements

does not open the file but requires exclusive access

No

FSEDIT procedure

update

Yes

PRINT procedure

input

Yes

SORT procedure that replaces original data set with sorted one

output

No

SQL procedure to modify, add, or delete observations

update

Yes

SQL procedure with CREATE TABLE or CREATE VIEW statement

output

No

SQL procedure to create or remove integrity constraints or indexes

utility

No

Buffer Allocation A buffer is a reserved area of memory that holds a segment of data while it is processed . The number of allocated buffers determines how much data can be held in memory at one time.

The number of buffers is not a permanent attribute of a SAS file; that is, it is valid only for the current SAS session or job. When a SAS file is opened, a default number of buffers for processing the file is set. The default depends on the operating environment but typically is a small number, for example, one buffer. To specify a different number of buffers, you can use the BUFNO= data set option or system option.

When the SASFILE statement is executed, SAS automatically allocates the number of buffers based on the number of data set pages and index file pages (if an index file exists). For example:

If a file that is held in memory increases in size during processing, the number of allocated buffers increases to accommodate the file. Note that if SASFILE is executed for a SAS data set, the BUFNO= option is ignored.

I/O Processing An I/O (input/output) request reads a segment of data from a storage device (such as disk) and transfers the data to memory, or conversely transfers the data from memory and writes it to the storage device. When a SAS data set is opened by the SASFILE statement, data is read once and held in memory, which should reduce the number of I/O requests.

CAUTION:

Using the SASFILE Statement in a SAS/SHARE Environment The following are considerations for using the SASFILE statement with SAS/SHARE software:

Comparisons

Examples

Example 1: Using SASFILE in a Program with Multiple Steps

The following SAS program illustrates the process of opening a SAS data set, transferring its data to memory, and reading that data held in memory for multiple tasks . The program is composed of steps that read the file multiple times.

libname mydata ' SAS-data-library '; sasfile mydata.census.data open; [1] data test1; set mydata.census; [2] run; data test2; set mydata.census; [3] run; proc summary data=mydata.census print; [4] run; data mydata.census; [5] modify mydata.census; . . (statements to modify data) . run; sasfile mydata.census close; [6]

[1]  

Opens SAS data set MYDATA.CENSUS, and allocates the number of buffers based on the number of data set pages and index file pages.

[2]  

Reads all pages of MYDATA.CENSUS, and transfers all data from disk to memory.

[3]  

Reads MYDATA.CENSUS a second time, but this time from memory without additional I/O requests.

[4]  

Reads MYDATA.CENSUS a third time, again from memory without additional I/O requests.

[5]  

Reads MYDATA.CENSUS a fourth time, again from memory without additional I/ O requests. If the MODIFY statement successfully changes data in memory, the changed data is transferred from memory to disk at the end of the DATA step.

[6]  

Closes MYDATA.CENSUS, and frees allocated buffers.

Example 2: Specifying Passwords with the SASFILE Statement

The following SAS program illustrates using the SASFILE statement and specifying passwords for a SAS data set that is both read-protected and alter-protected:

libname mydata ' SAS-data-data-library '; sasfile mydata.census (read=gizmo) open; [1] proc print data=mydata.census (read=gizmo); [2] run; data mydata.census; modify mydata.census (alter=luke); [3] . . (statements to modify data) . run;

[1]  

The SASFILE statement specifies the read password, which is sufficient to open the file.

[2]  

In the PRINT procedure, the read password must be specified again.

[3]  

The alter password is used in the MODIFY statement, because the data set is being updated.

Note: It is acceptable to use the higher-level alter password instead of the read password in the above example.

See Also

Data Set Option:

System Option:

The SERVER Procedure in SAS/SHARE User s Guide .

Категории