How does memory management work in SAS?

Reply
Community Manager
Posts: 2,757

How does memory management work in SAS?

This question appeared on Quora, where the original poster was wondering about SAS memory management and whether there was a garbage collection mechanism.

 

I replied with a relatively simplified answer.  It's not technically deep, but I hope it helps those who are getting started with SAS programming and might be looking for how memory works compared to other programming languages.  Here it is; if you can improve on it from a practitioner standpoint, feel free to add to the discussion.  If we get a good result we can create an official article for our SAS Communities Library.

 


For the purposes of this answer, I'm going to assume that the question is about the SAS programming language. That is, as a SAS programmer, what do I need to know about how memory is managed as my SAS program is running?

 

SAS manages the memory for you, so it's similar to Java or .NET in that way. But there isn't a garbage collection mechanism per se. SAS programs consist of a series of "steps" -- the DATA step and PROC steps (for SAS procedures). For the most part, memory is allocated as needed during the running step, then released when the step is complete.

 

Some SAS procedures can use a lot of memory during the course of their work, and you can run out of memory when working with large data or data sets with large cardinality. For example, PROC FREQ can compute n-way frequencies quickly, but if the variables you're analyzing have lots of distinct values, you can bump into memory limits. When this happens, SAS will issue an ERROR message to the SAS log indicating that there wasn't enough memory to complete the operation.

 

The SAS DATA step also offers some constructs that are inherently memory-dependent. The most popular is the hash object, which allows you to load lots of data values into memory and manipulate them quickly. It's good for building fast data management algorithms, as long as the data values can fit into memory.

 

Finally, when we talk about memory management in SAS, we also have to address the WORK area: the temporary scratch space on disk where SAS can write files as intermediate results while SAS procedures run. In practice, most SAS programs that deal with large data sets will run into WORK space limitation before they hit memory constraints. On administered SAS environments, it's important to ensure that SAS programs have access to enough WORK space (ideally with fast I/O performance) to accomplish their work.

 

For more admin-friendly tips, see this series of blog posts from my colleague Margaret Crevar.

Valued Guide
Posts: 3,208

Re: How does memory management work in SAS?

You coudl have answered SAS (data-step / procs) is working different as to common 3GL languages or OS systems (java).
SAS is using java or the OS for memory management when needed. Running java classes. File IO done by OS calls.

Every SAS step is  a working-unit not intended to leave something behind in memory. The clean-up is done at every boundary.
With a datastep the PDV (Program Data Vector) is set-up fixed after compilation. As being fixed memory management is not applicable.

The PDV is used wirh automatic looping on the data processing. This is a feature not present at most other languages. This automatic is confusing and also the power why programmed memory for addtional loops is not applicable.
   

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 1 reply
  • 659 views
  • 4 likes
  • 2 in conversation