Monday, February 29, 2016

Hack 2.5 Obtaining the Computer Memory Available to SAS


SAS Programming Professionals, 

Did you know that you can easily obtain the amount of computer memory available to SAS? 

 You can do so by using the undocumented XMRLMEM option.  XMRLMEM is an undocumented diagnostic option that can come in handy when you are considering allocating a bushel-full of buffers or considering doing some big-time hashing. 

Here is how it might look in action:

            data _null_;
      
      format available_memory 
             available_memory_K 
             available_memory_M 
             available_memory_G comma20.;

      available_memory = input(getoption('xmrlmem'),20.);
      available_memory_K = available_memory/1024;
      available_memory_M = available_memory_K/1024;
      available_memory_G = available_memory_m/1024;

      put "available_memory = " available_memory;
      put "available_memory_K = " available_memory_K;
      put "available_memory_M = " available_memory_M;
      put "available_memory_G = " available_memory_G;

      run;

The code, above, will give you the total number of bytes of real memory available.  (It does not count the operating system's virtual memory; only real memory).  You can simply divide this number by 1024 to get it into K's... or whatever to get it into Megs or Gigs as per the example.  The log from executing this program on the author’s PC looks like this:

       1    data _null_;
       2
       3    format available_memory
       4           available_memory_K
       5           available_memory_M
       6           available_memory_G comma20.;
       7
       8    available_memory = input(getoption('xmrlmem'),20.);
       9
       10   available_memory_K = available_memory/1024;
       11   available_memory_M = available_memory_K/1024;
       12   available_memory_G = available_memory_m/1024;
       13
       14   put "available_memory = " available_memory;
       15   put "available_memory_K = " available_memory_K;
       16   put "available_memory_M = " available_memory_M;
       17   put "available_memory_G = " available_memory_G;
       18
       19   run;

available_memory = 1,713,319,936
available_memory_K = 1,673,164
available_memory_M = 1,634
available_memory_G = 2

Is that all I've got?  It looks like a computer memory upgrade is in order!

Best of luck in all of your SAS endeavors!

----MMMMIIIIKKKKEEEE

(aka Michael A. Raithel)

Excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers



I plan to post each and every one of the hacks in the book to social media on a weekly basis.  Please pass them along to colleagues who you know would benefit.