OPEN Function


OPEN Function

Opens a SAS data set

Category: SAS File I/O

Syntax

OPEN (< data-set- name <, mode >>)

Arguments

data-set-name

  • specifies the SAS data set to be opened. The name 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, they are ignored. All other data set options are valid.

mode

  • 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

Details

OPEN opens a SAS data set (a SAS data set 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.

By default, a SAS data set is opened with a control level of RECORD. For details, see the 'CNTLLEV= Data Set Option' on page 13 . 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 when data sets are opened in INPUT or UPDATE mode. Otherwise, data sets are opened with sequential access, and a system-level warning is set.

Examples

  • This example opens the data set PRICES in the library MASTER using INPUT mode. Note that in a macro statement you do not enclose character strings in quotation marks.

     %let dsid=%sysfunc(open(master.prices,i));  %if (&dsid = 0) %then     %put %sysfunc(sysmsg());  %else     %put PRICES data set has been opened; 
  • This example passes values from macro or DATA step variables to be used on data set options. It opens the data set SASUSER. HOUSES , and uses the WHERE= data set option to apply a permanent WHERE clause. Note that in a macro statement you do not enclose character strings in quotation marks.

     %let choice = style="RANCH";  %let dsid=%sysfunc(open(sasuser.houses                    (where=(&choice)),i)); 

See Also

Function:

  • 'CLOSE Function' on page 438




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net