Functions and CALL Routines |
Category: | SAS File I/O |
Syntax | |
Arguments | |
Details | |
Examples | |
See Also |
Syntax |
OPEN(<data-set-name <,mode <,generation-number <,type>>>>) |
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. |
is a character constant, variable, or expression that specifies the type of access to the data set:
Default: | I |
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. |
is a character constant and can be one of the following values:
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.
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 |
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));
This example shows how to check the returned value for errors and to write an error message from the SYSMSG function.
data _null_; d=open('bad','?'); if not d then do; m=sysmsg(); put m; abort; end; ... more SAS statements ...; run;
See Also |
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.