Previous Page | Next Page

Functions and CALL Routines

OPEN Function



Opens a SAS data set.
Category: SAS File I/O

Syntax
Arguments
Details
Examples
See Also

Syntax

OPEN(<data-set-name <,mode <,generation-number <,type>>>>)


Arguments

data-set-name

is a character constant, variable, or expression that specifies the name of the SAS data set or SAS SQL view to be opened. The value of this character string should be of the form

<libref.>member-name<(data-set-options)>
Default: The default value for data-set-name is _LAST_.
Restriction: If you specify the FIRSTOBS= and OBS= data set options, they are ignored. All other data set options are valid.
mode

is a character constant, variable, or expression that specifies the type of access to the data set:

I

opens the data set in INPUT mode (default). Values can be read but not modified. 'I' uses the strongest access mode available in the engine. That is, if the engine supports random access, OPEN defaults to random access. Otherwise, the file is opened in 'IN' mode automatically. Files are opened with sequential access and a system level warning is set.

IN

opens the data set in INPUT mode. Observations are read sequentially, and you are allowed to revisit an observation.

IS

opens the data set in INPUT mode. Observations are read sequentially, but you are not allowed to revisit an observation.

Default: I
generation-number

specifies a consistently increasing number that identifies one of the historical versions in a generation group.

Tip: The generation-number argument is ignored if type = F.
type

is a character constant and can be one of the following values:

D

specifies that the first argument, data-set-name, is a one-level or two-level data set name.

The following example shows how the D type value can be used:

rc = open('lib.mydata', , , 'D');               
                                 
Tip: D is the default if there is no fourth argument.
F

specifies that the first argument, data-set-name, is a filename, a physical path to a file.

The following examples show how the F type value can be used:

  rc = open('c:\data\mydata.sas7bdat', , , 'F');                                
  rc = open('c:\data\mydata', , , 'F');                                         
Tip: If you use the F value, then the third argument, generation-number, is ignored.

Note:   If an argument is invalid, OPEN returns 0. You can obtain the text of the corresponding error message from the SYSMSG function. Invalid arguments do not produce a message in the SAS log and do not set the _ERROR_ automatic variable.   [cautionend]


Details

The OPEN function opens a SAS data set, DATA step, or a SAS SQL view and returns a unique numeric data set identifier, which is used in most other data set access functions. OPEN returns 0 if the data set could not be opened.

If you call the OPEN function from a macro, then the result of the call is valid only when the result is passed to functions in a macro. If you call the OPEN function from the DATA step, then the result is valid only when the result is passed to functions in the same DATA step.

By default, a SAS data set is opened with a control level of RECORD. For details, see the CNTLLEV= Data Set Option . An open SAS data set should be closed when it is no longer needed. If you open a data set within a DATA step, it will be closed automatically when the DATA step ends.

OPEN defaults to the strongest access mode available in the engine. That is, if the engine supports random access, OPEN defaults to random access. Otherwise, data sets are opened with sequential access, and a system-level warning is set.


Examples


See Also

Functions:

CLOSE Function

SYSMSG Function

Previous Page | Next Page | Top of Page