SAS Utilities: cleanwork

Barry Stevens
April 29, 2020

When a user starts and runs code in a SAS session, a number of temporary folders and files are created in the SASWork and SASUtil locations.

If that session completed and exits normally these folders and files are removed, however some SAS sessions exit abnormally, and these folders and files are not removed. Over time, if not managed, these files and folders can cause issues with diskspace and the operation of other SAS sessions (if SASWork or SASUtil disk is full SAS can’t start).

How do you manage these files? How do you know what folders and files to remove?

Luckily SAS have a utility, cleanwork, that can be scheduled to do this for you.

[Disclaimer from this point on I will be taking about the SAS9.4 running on LINUX OS and how to do, however same can be applied on other OS.]

The documentation for the UNIX cleanwork utility can be found here.

So, what is the cleanwork utility?

It is an executable that ‘Deletes any leftover Work directories, utility directories, or both, whose associated SAS process has ended.’

The syntax is pretty simple,

cleanwork directory <-n> <-v> <-hostmatch> <-log logfile>

An example of how we have used (it is suggested by SAS that this is run by the root account)

/opt/sas/app/sas/SASFoundation/9.4/utilities/bin/cleanwork /saswork /sasutil > /opt/sas/logs/cleanwork/cleanwork_$HOSTNAME.log

Once you have got the syntax right, you may want to schedule daily – just make sure it is root schedule being edited in crontab by using the following command.

sudo crontab -u root -e

Our example:

30 0 * * * /opt/sas/app/sas/SASFoundation/9.4/utilities/bin/cleanwork /saswork /sasutil > /opt/sas/logs/cleanwork/cleanwork_$HOSTNAME.log 2>&1

Once you have scheduled and running, hopefully you’ll no longer see any defunct SASWORK or SASUTIL folders filling your diskspace.

You learn something everyday.

Barry, Preventer of Chaos.

Barry Stevens is part of our Data Ops team who specialises in SAS Administration, helping you prevent chaos.

Connect with Barry on LinkedIn or read some of his other blogs here.

Copyright © 2019 OptimalBI LTD.