BookmarkSubscribeRSS Feed
Nishant2000
Fluorite | Level 6

Hi All,
I do understand that when we run a query in SAS all the temporary tables created under the work library are deleted automatically once the code/session ends, but I wanted to know how does it get deleted? I mean, what function runs in the backend which does this activity, and how it is called, as we don't write any such function in our code. 

On similar lines, we do understand a  .lck file is created when the job is executing and if the code completes the .lck file is renamed from sas7bdat.lck to sas7bdat, or if failure the .lck file is deleted. So, my question is how does SAS perform these kinds of activities? And how are the functions called automatically when we don't write any such query in SAS code. 

5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

That's part of how SAS works.

There many more interesting questions if you want to look under the hood.

For example you can look at proc sort and its workings (use the DETAILS option) . Or how to make best use of indexes. Or how proc sql merges tables (use the _METHOD option).

 

Nishant2000
Fluorite | Level 6
Thank you Chris, but this question is also important as sometimes you will notice that the .lck or the temporary files from work is not deleted even if the job is succ or fail which can cause space issues. So I wanted to understand how the SAS work.
ChrisNZ
Tourmaline | Level 20

> not deleted even if the job is succ 

SAS always deletes the works folder when closing normally. Always. Unless you choose otherwise and the WORKTERM option is used.

 

> which can cause space issues

this might interest you:    https://support.sas.com/kb/8/786.html

Kurt_Bremser
Super User

WORK directories (and the files within) are always removed on graceful termination. For remnants of crashed,  sessions, use cleanwork.

Crashed sessions are in no way "normal" and need to be investigated.

Kurt_Bremser
Super User

When SAS terminates gracefully, it removes the whole directory of the WORK library with one system call (think of rm -rf in UNIX).

For directories that remain when a SAS session crashes, SAS provides the cleanwork utility, which a diligent SAS admin will run periodically (scheduled!) on the root work directory.

Similarly, removing/renaming of files during data steps is done by the SAS executable as part of the data step engine; these are internal calls you do not have access to, and als do not need.

If you manually need to work with other files, SAS provides functions like FDELETE for use in data step code.

 

Keep in mind that data steps are compiled; the data step language is a very high-level language, which means that the compiler does a lot of work for you that you would have to do yourself in other languages (think of the difference between a SQL query sent to a DBMS and coding the same action in C or Go).

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 620 views
  • 2 likes
  • 3 in conversation