Hello
In order to check if a data set has index I saw the following code:
%let dsid=%sysfunc(open(sashelp.cars));
%put dsid=&dsid; /**2**/
%let indx=%sysfunc(attrn(&dsid,isindex));
%put indx=&indx; /**0**/
My question-
&dsid get value 2
what does it mean?
What exactly &dsid is calculating?
In code : %let indx=%sysfunc(attrn(&dsid,isindex));
why the argument is &dsid and not data set name (sashelp.cars)?
http://support.sas.com/kb/43/637.html
From the docu for the 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.
From experience:
The first time you use the open() function in a SAS session, the function will return a value of 1 if successful. Any time you execute the function again in the same session the return value gets incremented by 1.
Think of this value as a pointer to your opened data set that you then use in other functions.
The value returned by OPEN() is the something called a "file handle" in a lot of programming languages. It is essentially a pointer to the open file that you can pass to other functions that operate on files, like the ATTRN() function (and the CLOSE() function) used in that example.
You cannot just use the filename (or in this case the dataset name) because you might have the same dataset open multiple times for different purposes.
Consider this simple SAS program to do a quick sort of SASHELP.CLASS by SEX.
data class ;
set sashelp.class(where=(sex='F'))
sashelp.class(where=(sex='M'))
;
run;
I highly recommend Maxim number 1, it's not that hard to do.
Open() Function - Details:
Bart
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.