Tip: How to close all data sets in SAS Enterprise Guide


It has a simple cause: the data set that your program is trying to write (or rewrite) is open in the data viewer. With regard to this data file, your program is in contention with the SAS Enterprise Guide application.

Usually SAS Enterprise Guide closes all open data sets before running a program or task, and that's meant to help you avoid this error. But sometimes a data set file remains open for one reason or another, and the conflict results in the error message. Fortunately, there is a simple fix.

Close All data sets window

Select Tools->View Open Data Sets. The View Open Data Sets window shows the names of the data files that SAS Enterprise Guide has open. And it offers a convenient Close All button to clear the list. Closing the data doesn't affect the contents of the file or its place in your project. It simply removes the lock that SAS Enterprise Guide is holding on the file.

If you are running multiple SAS Enterprise Guide sessions, it's possible for one session to have a lock on a file that you're trying to update in another session. The View Open Data Sets window shows only those data sets from your current session, so be sure to check your other projects if you're multitasking.

The default behavior -- close all data before running SAS programs -- is controlled in Tools->Options->SAS Programs. If you don't want SAS Enterprise Guide to close your data windows, clear that checkbox. (It's difficult for me to imagine why you would do that. but hey, we have options for everything.)

About Author

Chris Hemedinger

+Chris Hemedinger is the Director of SAS User Engagement, which includes our SAS Communities and SAS User Groups. Since 1993, Chris has worked for SAS as an author, a software developer, an R&D manager and a consultant. Inexplicably, Chris is still coasting on the limited fame he earned as an author of SAS For Dummies.

29 Comments

Leonid Batkhan on October 18, 2016 9:43 am It's a great tip. Thank you, Chris.
Is there a programmatic way to do that?

Chris Hemedinger

Chris Hemedinger on October 18, 2016 9:45 am

Leonid, no, there isn't. Although I'm sure you could use a key macro tool like AutoHotkey to automate the operation.

It looks like you can use open and close to close datasets programmatically, but not all at once. Unless there is a way to get a list of data-set-id values programmatically.

Prasanna Sondur on October 18, 2016 10:02 am

I used to close and open SAS EG session to overcome this common hiccup. Very useful info. Thanks for sharing!

This is a great tip! It would make a great submission to sasCommunity.org.

Kimball Price on November 17, 2016 6:15 pm

Great advice. It doesn't happen often but once in awhile a table will be mysteriously locked and this would be good way to see when that happens. But . in tools ->> View Open Data Sets it is greyed out for me- unavailable on my E.G. setup. Any remedies ?

Chris Hemedinger

Chris Hemedinger on November 18, 2016 9:31 am

Kimball, the menu item is disabled when you don't have any data in the project, or when no data sets are open.

Chris, this is great info (as always) for cases when you are a lone shooter in the data pond, however in my case this error is more often the result of another user having the dataset open in their session. While I use the well written "lockitdown" macro to catch these scenarios, is there not a simple way to configure SAS to allow the owner to write, despite a non-owner reading the dataset?? Seems a bit counter-intuitive to prevent the owner from updating their data sets when a non-owner is using it.

Tricia Aanderud on August 14, 2017 1:44 pm Was this option "moved" or "removed"? I don't see it in 7.13.

Chris Hemedinger

Chris Hemedinger on August 14, 2017 1:54 pm

Nope, it's there! In the Tools menu, near the bottom. It's enabled only when there are one or more open data sets, but the menu item is always visible.

Thanks for the tip, but like another commenter experienced, I currently have a dataset that is reporting as being open and generating the error you mentioned, but 'View Open Data Sets' is greyed out. I was working the I/O function, so I tried writing a loop to try closing dataset IDs, but that didn't work either. I also can't force PROC DATASETS to delete the set (it's just a dataset in work I can easily recreate). Looks like I'm stuck restarting my session to close the set free up that dataset name for use again.

Chris Hemedinger

Chris Hemedinger on August 17, 2017 3:10 pm

This method can track only what EG has open -- but if your SAS process has something locked outside of the interface, this action won't close it.

That option is grayed out

Chris Hemedinger

Chris Hemedinger on March 2, 2018 12:03 pm

The option is enabled only when one or more data sets are opened -- and open by SAS Enterprise Guide. Lots of actions will close the data sets implicitly (like running code), so you might find the option not applicable in many cases. It's there when you need it.

Michael Tuchman on January 7, 2020 7:14 pm

So, in the case when we're still getting locked out, but there is no DS open in EG, what might be some next steps to take? I can get specifics by opening a ticket; this question is just about generalities.

Chris Hemedinger

Chris Hemedinger on January 8, 2020 9:05 am

If EG doesn't have the data set open (by any user), it could still be locked by a running SAS job. You might need access to the OS to use the lsof command (Linux) or the handle.exe or Resource Monitor on Windows. By the way, SAS Enterprise Guide v8 releases open data files quickly, by default after 3 minutes of idle time.

Meenakshi on January 16, 2020 12:10 pm How to do this in BASE sas. I am not seeing the option View Open Data Sets in Tools

Chris Hemedinger

Chris Hemedinger on January 16, 2020 1:43 pm A community member shared an approach you can use. This macro:
%macro closevts; %do i=1 %to 20; dm 'next VIEWTABLE:; end;'; %end; %mend;
You could assign that to a function key to run it.

is this still available in 8.1? I am not able to see it :(

Chris Hemedinger

Chris Hemedinger on February 27, 2020 4:02 pm

In EG 8.1 and later, the data sets close automatically after just a short period of idle time. The data set locks are released quickly, so the need to close ALL data at once is minimized. That said, you can use File->Close All Items. And you can right-click on any tab and select Close, Close Others, or Close All.

Neville Cope on August 14, 2020 4:25 am

None of these helped for me. Every now and again, when continually running big programs with lots of output data sets and continually viewing them in the output data tab, EG seems to hang onto the lock for one. When I run a snippet of code subsequently I get errors that the data set is locked, but i've not tabs available to close. I tried the "Close All" but that didn't do anything. I have to kill the session and start again :(

Chris Hemedinger

Chris Hemedinger on August 15, 2020 1:44 pm

In EG 8.1 and later, it shouldn't be such an issue. EG locks the data tables only for a short time (configurable). If all data views are closed but you still see data is locked, it might be another process, or running code. Or even another user if it's in a shared space. Or, if working with Excel data, MS Excel can also lock the file.

Chris Greene on August 11, 2021 2:18 pm

In EG 8.3 (maybe 8.1 too but I'm using 8.3) there is an option under TOOLS > OPTIONS > DATA > PERFORMANCE to "Unlock all open data before running code" that did the trick for me after loosing the SAS Programs option for "Close all data before running code" that was in EG 7.1

Michael Tuchman on November 4, 2021 11:06 am Chris Greene - thank you! This did the trick.

Chris Greene's tip is what works to get rid of the message
ERROR: You cannot open WORK.xxx.DATA for output access with member-level control because WORK.xxx.DATA is in use by you in resource environment IOM ROOT COMP ENV.
and seems to make the statement that the default behaviour is to close all data before running SAS programs?