%let dsid=%sysfunc(open(sasuser.houses));
%put The current open data set
is %sysfunc(dsname(1));
I just copied this from the sas documentation site, but it is throwing error. I tried using datastep method as well, rather than macro function , but it is still the same. Below is the log:
338 %let dsid=%sysfunc(open(sasuser.houses));
339 %put The current open data set
340 is %sysfunc(dsname(1));
WARNING: Argument 1 to function DSNAME referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
The current open data set is
341
Do anyone know why so?
Most likely cause would be you don't have a dataset named sasuser.houses, or you have run the code more than once. If you run the code twice (without closing the dataset you have opened), the value of DSID will be 2 (if the dataset is present).
I would suggest adding a %PUT statement to check the value of DSID. 0 means the dataset was not found and could not be opened.
Also I would use the macro variable DSID inside the DSNAME function instead of hardcoding the value 1. So try:
%let dsid=%sysfunc(open(sashelp.class));
%put dsid=&dsid ;
%put The current open data set is %sysfunc(dsname(&dsid));
And that should work. Then try changing from sashelp.class to sasuser.houses and see if it still works.
Most likely cause would be you don't have a dataset named sasuser.houses, or you have run the code more than once. If you run the code twice (without closing the dataset you have opened), the value of DSID will be 2 (if the dataset is present).
I would suggest adding a %PUT statement to check the value of DSID. 0 means the dataset was not found and could not be opened.
Also I would use the macro variable DSID inside the DSNAME function instead of hardcoding the value 1. So try:
%let dsid=%sysfunc(open(sashelp.class));
%put dsid=&dsid ;
%put The current open data set is %sysfunc(dsname(&dsid));
And that should work. Then try changing from sashelp.class to sasuser.houses and see if it still works.
Thank you. @Quentin You're right!
II. is also true for all similar operations (FOPEN/FCLOSE, DOPEN/DCLOSE and so on)
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.