Check Available Memory To SAS Session
When you think about the performance of your SAS code, you often think about the number of Input/Output operations and how to reduce these. There are several ways to reduce the number of I/O operations. You can for example Read An Entire Data Set Into Memory. Or you can Create A Library That Resides In Memory. In both cases, you need to answer the question: “How much RAM is available to my session?”. In this example, we check the available RAM to the current session.
SAS Code Example To Check Available Memory
I have written a small SAS program that writes the available RAM to the log. The code uses the GETOPTION Function to retreive the value of the undocumented XMRLMEM Option, that holds the value of the available memory.
data _null_; mem = input(getoption('xmrlmem'),20.2)/10e6; format mem 20.2; put "You have " mem "GB memory available"; run;
The XMRLMEM Option stores the numeric value of the available RAM in bytes. Therefore, we divide by 10e6 to convert to GB, which is the usual reference unit of Random Access Memory (RAM).
I have 1.71 GB of memory available to my session. This is an important piece of information from a performance point of view. If you need to sort data sets larger than this, perhaps you should increase the available memory with the MEMSIZE Option at startup. Furthermore, think about how much RAM you allow different procedures to use. For example, control how much memory you let the Sort Procedure utilize with the SORTSIZE System Option. I write about the SORTSIZE Procedure option in the blog post Three PROC SORT Options You Should Know.
Besides the two examples, that I link to in the top of this page, there are several other ways to increase performance of your code. Consult the SAS Documentation at the Optimizing System Performance to see other ways.
Also, when we talk about performance of your code, there is no better book than High Performance SAS Code. I recommend the book at my blog post What SAS Books Are On My Shelf?
Also, I use the very trick from this page in the blog posts How Much Memory Does My Hash Object Occupy?, Three Basic Techniques to Reduce SAS Hash Object Size and Two Advanced Techniques to Reduce SAS Hash Object Size.
You can download the entire code form this example here.