Hello,
I have a question on %sysfunc(open())
I thought %sysfunc(open()) is open a dataset, which give 0 or 1 to show whether the dataset is opened successfully. I accidentally forgot to close the file, and found that if I keep running following code, &_dsid is not a 0,1 value, instead it will keep going up to 2, 3, 4.
Can anyone explain what _dsid really is?
and also what varnum(1, &_colvar) is. why 1 instead of not a dataset name here?
%let _dsid=%sysfunc(open(sashelp.baseball));
%put &_dsid;
%let _colvar=team;
%let _varnum=%sysfunc(varnum(&_dsid,&_colvar));
%put &_varnum;
Thanks.
Maxim 1: Read the Documentation.
From OPEN Function
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 want to know what %SYSFUNC(OPEN()) returns then ignore the use of the %SYSFUNC() wrapper macro function and just look at the documentation of the actual OPEN() function.
It does NOT return a boolean 0/1 answer. Instead it returns the File handle (or in this case what the documentation calls a table-id) that is required to be used by the other functions that can operate on an open dataset.
If the OPEN() fails then it returns 0 instead of an actual number.
If the OPEN() succeeds then you need to make sure to call CLOSE(), passing the in the file handle OPEN() generated, so you close it.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.