BI Tools

Tips and tricks for building information maps, OLAP cubes, reports, and dashboards

BI Admin

Learn your way around a SAS BI installation.

Visual Analytics

Learn your way around the SAS Visual Analytics tool

Coding & Data

Extract, transform, and load your data into the SAS BI toolset

Stored Processes

Create and design stored processes like a rock star

Home » BI Admin

Administration: Cleaning Up the WORK Library Automatically in UNIX

Submitted by on 2012-03-19 – 7:54 AM 7 Comments

sas clean your unix work directory with cron job

Here is a quick tip for keeping the WORK library clean in a UNIX/Linux environment.  Most of the time SAS manages the cleanup process very well but sometimes orphaned processes can leave unwanted data lying around which can build up over time.  This tip is only applicable for UNIX or Linux environments.  SAS does come with a cleanwork utility which can be configured.  This approach could be used as a last resort in case the cleanwork utility fails.


Use a Shell Script for UNIX Heavy Lifting

This simple shell script will find all WORK directories created by SAS sessions and recursively remove everything within each directory older than a set time frame.  The joys of shell scripting!  🙂



find $WORK/* -mtime +3 -exec rm -rf {} \;

exit 0

The WORK variable is set to the physical path of the WORK library on the compute server.  The number 3 represents the number of days since the file was last modified.  When this script is run, it initiates the find command which finds everything starting from the set directory with a last modified date older than 3 days, then forcibly removes everything within.  To prevent any permission problems, it should be run as ‘root’ or any other super user. 

Why Not Schedule It?

This shell script can be scheduled with cron or whatever scheduling system manages the server.  Personally I prefer cron because it just works!  More information about cron can be found here.

Learn all about SAS BI

You can learn more about SAS Business Intelligence from the "SAS BI Bible." Take a peek inside the Building Business Intelligience with SAS book.

The following two tabs change content below.
Spread the love

Tags: , ,


  • Steve Overton says:

    Gotta love the “rogue” users who always want to find a way to store more data somewhere! I experienced the same problem at a client one time, which is where this script spawned.

  • Ronan says:

    Hi Steve,

    Thanks for providing us with the script. In fact, both approaches are complementary from my experience : it is true that the cleanwork utility does perfectly its job, but it does not wipe out all content of SASWORK location. I have had some users whon, unfortunately (for me) realized that they could use the SASWORK root folder as free extra storage for their own purpose and , guess what, they didn’t prefix their ghost subfolders with SAS_work ou SAS_util 😉 … So a rm -rf command proved necessary in addition to the cleanwork already scheduled, just to be sure nothing else has been left out by the garbage collector.
    In theory, it would even be possible to modify the cleanwork micro-code (written in C) with a (recursive) file delete option and recompile it. A version of the code is freely available at the following address :

    All the best

  • Looks like you have to have all kinds of tools in your Admin toolbox. Do you think SAS is easier to administer on Windows or Unix?

  • Steve Overton says:

    I agree, the cleanwork utility is great and the preferred route. This is a more down and dirty method and should be carefully planned. I’ve been in some corporate environments that also like having this script running as a backup because its simple. One particular client I have worked with had a large Enterprise Guide user base that consumed nearly a terabyte of WORK storage on a weekly basis due to users leaving EG running over night or for a few days. In most cases, after a few days of inactivity, they had a policy to wipe it clean. So in addition to the Metadata server, STP server, and Pooled Workspace Server, the regular workspace server should also be considered.


  • Stig Eide says:

    I would recommend to use the CLEANWORK utility that comes with the SAS installation.
    If you are running a SAS Metadata server, Stored Process Server or Pooled Workspace Server, then it would not be possible to delete a work folder based on age, because those processes could be weeks old without something being wrong.
    Stig Eide

  • STéphane

    I have heard of kill -9 but not -15. Hmmm …. what does it mean?


  • Hi,

    there is the CLEANWORK utility on UNIX platform also. That manage that and the kill-15 command.