DATA Step, Macro, Functions and more

How can I get data-set-ids of all the data sets that are open?

Reply
New Contributor
Posts: 2

How can I get data-set-ids of all the data sets that are open?

Is there a way to find out the data-set-ids of all the data set that are currently open? It happens when I don't know the data-set-ids but I want to close all the data sets.

Many thanks!

Super User
Posts: 10,487

Re: How can I get data-set-ids of all the data sets that are open?

Are you using this in macro code or a data step? The data step version closes all data sets at the end of the data step execution.

You are responsible for maintaining the dataset id variables. You should assign a unique variable to hold each dataset identifier. If you aren't doing that then you need to pay attention to the recommendation from the documentation: Close all SAS data sets as soon as they are no longer needed by the application.

 

Generally the worse thing that will happen in you attempt to close a set that isn't open is the return code will be negative. If you don't the variables that are holding the IDs then you really need to rewrite some code.

 

What are you doing that you need to have multiple datasets open using the open/close functions in the first place?

New Contributor
Posts: 2

Re: How can I get data-set-ids of all the data sets that are open?

Thanks so much for the reply. I am trying to use it in a macro. But I think your suggestion is correct. I should manage the dataset correctly when I use it instead of trying find the dataset id and closing the dataset.

Super User
Posts: 10,487

Re: How can I get data-set-ids of all the data sets that are open?

Especially if you are doing this in some sort of loop. It gets easy to open multiple sets using the same id variable. At which point you can only get to that one dataset for closure.

Ask a Question
Discussion stats
  • 3 replies
  • 198 views
  • 0 likes
  • 2 in conversation