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 SAS Library That Resides In Memory. In both cases, you need to answer the question: “How much memory is available to my SAS session?”.

A Small SAS Code Example

I have written a small SAS program that writes the available memory 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;

SAS Available Memory Example

The XMRLMEM Option stores the numeric value of the available memory in bytes. Therefore, we divide by 10e6 to convert to GB, which is the usual reference unit of RAM.

I have 1.71 GB of memory available to my SAS session. How much do you have?

Summary

Besides the two examples, that I link to in the top of this page, there are several other ways to increase performance of your SAS code. Consult the SAS Documentation at the Optimizing System Performance to see other ways.

Also, when we talk about performance of you SAS 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?

You can download the entire code form this example here.