%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)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: