Finding and deleting orphaned SAS WORK and SAS Utility directories


SAS administrators often ask for a utility that can detect orphaned SAS WORK and SAS Utility directories on their back-end SAS compute systems. These orphaned directories result when a SAS Enterprise Guide or any other SAS GUI application is terminated incorrectly, and the SAS session does not terminate properly.

SAS has written utilities to detect these directories and delete them.

For UNIX/Linux, you use the cleanwork utility in the !SASHOME/bin/utilities directory that has been shipping with SAS since SAS 8.2.  The utility deletes any leftover SAS WORK and SAS Utility directories that were associated with a SAS process that has ended.   For more details, please refer to the cleanwork command documentation in the SAS 9.4 Companion for UNIX Environments.

For Windows, SAS has recently been promoting the SAS Disk Cleanup Handler Utility.  This utility searches for and cleans any temporary files that SAS generates, as well as any SAS WORK and SAS Utility directories.  SAS Disk Cleanup Handler is a COM hook into the Microsoft Disk Cleanup Handler (cleanmgr.exe).  For more details, please refer to the SAS Disk Cleanup Handler Utility documentation in the SAS 9.3 Companion for Windows.  Please note that this version of the utility is available with SAS 9.2 and SAS 9.3.

Starting with SAS 9.4M2, there is a new stand-alone utility – cleanwork.exe – that you can use with any version of SAS, starting with SAS 6.

We have placed this utility along with its documentation on the SAS FTP download page:

Many of our SAS administrators who are using these utilities have them scheduled to run once a week or once a month, depending on the frequency of their SAS users incorrectly terminating SAS sessions or the amount of free space they have in the SAS WORK and SAS Utility file systems.




About Author

Margaret Crevar

Manager, SAS R&D Performance Lab

Margaret Crevar has worked at SAS since May 1982. She has held a variety of positions since then, working in sales, marketing and now research and development. In her current role, Crevar manages the SAS Performance Lab in R&D. This lab has two roles: testing future SAS releases while they're still in development to make sure they're performing as expected; and helping SAS customers who are experiencing performance issues overcome their challenges.


  1. Hello Margaret,

    This is useful, kindly let me know if we can have duration also added as a parameter, like any session older than 24hrs to be cleaned up but not earlier to it.

  2. Margaret,

    Hope all is well. Can we use this prior to an image to reduce overall image size? I am running on a Windows Server instance and need to do an image prior to backup.


  3. Small correction: for Linux (and presumably UNIX), cleanwork is in the !SASHOME/utilities/bin/ directory, not the !SASHOME/bin/utilities directory.

  4. I understand that this is admin functionality but is there a command that any SAS programmer can run to get a list of workspace usage by all SAS user ids? Would be easy to contact one user, rather than send an email to the admin and wait to get the report and then send it to the entire team.

    • Margaret Crevar
      Margaret Crevar on

      NP, There are several ways to do this. One is via SAS RTM that has been part of SAS Grid (but this way may require administration privileges). However, starting with SAS 9.4 M3 a lot of the RTM functionality has been added to SAS Environment Manager, and part of that functionality is for you to be able to do real time monitoring of SAS jobs running on your system as a SAS user. More details can be found here:

      You can also look and writing a SAS job/macro that can be executed via SAS Enterprise Guide to get similar information. We can share this code with you if you would like.

      • I'm interested in the code for the SAS job/macro that can be executed via SAS Enterprise Guide to get similar information. Thanks.

    • Richard Collins on

      NP - check out worktop:

      It's a bash script which monitors your saswork mounts, highlighting those which breach a configurable threshold. Very simple to use, download, add execute rights and run. With a bit of tweaking of the workspace server config it can display the metauser for the sas session

  5. Handy - but these open up the disk space without actually cleaning the data from the drive, do they not? We've got sensitive data. What would be useful is a way to initiate a process to wipe the temporary files when the SAS session is shut down, by overwriting it with random bits.

    Has anybody heard of such a thing?

    • I checked with SAS R&D, and this is the first time they have heard of a request for this feature. Please remember that files come and go in the SASWORK area during the SAS session and when SAS shuts down properly they are deleted to make room for the next SAS session to create files in.

      With all the SAS sessions using a single directory/folder for SAS WORK, the space will be overwritten often, so that should help with making sure your sensitive data can not be restored.

      Please let me know if you have questions on this information.

      • Margaret,
        Using a single directory/folder for SAS WORK does not mean that all SAS sessions use the same disk areas. Even if files are stored in the same directory, they may be physically on different disk areas, especially when there is a lot of free space on the disk.

        • You are correct, but most companies SAS WORK area generally runs 75% full each day. So the odds of another SAS session creating a SAS WORK directory and writing over the disks from a previous SAS session are very high.

          Also, SAS does not write in contiguous disk space on a single disk, it writes the SAS data files across multiple disks. As soon as any segment of the previous SAS data file that was written is written over, then the entire SAS data file can not be restored.

  6. Michael A. Raithel on


    Great article as always!

    I have two questions:

    1. Is the Cleanwork Utility for Windows aimed solely at Windows servers, or will it also run on Windows workstations?

    2.Can the cleanwork.exe stand-alone utility be run on Windows workstations?

    Thank you.

    (aka Michael A. Raithel)

    • The cleanwork.exe will run on Windows Vista and newer. And Window Server 2008 R2 and newer. Hope that helps..

  7. Thanks for the information Margaret. However, based on my personal experience the 'cleanwork' utility does not delete the folders which are still locked by orphaned processes.

    Is there any way out of this?

    • Margaret Crevar on

      If the command is run by root it should delete all the SAS folders. Please let me know if this is not the case.

    • Kurt Bremser on

      You have to terminate the "dead" processes first. I have to do that regularly for CONNECT sessions where the client was simply turned off. After the owning process is gone from the process list, cleanwork does its duty.
      Killing other user's process requires superuser/system privilege, though.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top