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.

BASUG is hosting free webinars ! Check out recordings of our past webinars: https://www.basug.org/videos. Save the date for our in person SAS Blowout on Oct 18 in Cambridge, MA. Registration opens in September.

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.

BASUG is hosting free webinars ! Check out recordings of our past webinars: https://www.basug.org/videos. Save the date for our in person SAS Blowout on Oct 18 in Cambridge, MA. Registration opens in September.
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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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