BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
angird1990
Calcite | Level 5

%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?

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

View solution in original post

3 REPLIES 3
Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
angird1990
Calcite | Level 5

Thank you. @Quentin You're right!

Kurt_Bremser
Super User
  1. instead of a literal, use the result of the OPEN function
  2. whenever you use OPEN, also issue a CLOSE call in the same submit; make your code clean up after itself

II. is also true for all similar operations (FOPEN/FCLOSE, DOPEN/DCLOSE and so on)

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 638 views
  • 5 likes
  • 3 in conversation