Chapter 19: Introduction to Efficient SAS Programming STAT 541 Chapter 19: Introduction to Efficient SAS Programming ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina
SAS System Options to Track Resources We have already used STIMER CPU Time and Real Time FULLSTIMER tracks additional resources (though perhaps not as many as listed here) I/O swaps Number of buffers Buffer size Memory
SAS System Options to Track Resources My system’s output from FULLSTIMER: NOTE: PROCEDURE SORT used (Total process time): real time 0.04 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds Memory 88k OS Memory 10920k Timestamp 4/16/2012 11:26:43 AM
SAS System Options to Track Resources Typical considerations Real time/CPU time Increasing buffer size/# of pages vs. Memory Decreasing I/O vs. Memory 4
Benchmarking The chapters that follow will use benchmarking to study Memory Usage Data Storage Space Best Practices Efficient Sorting 5
Benchmarking SAS uses data sets of various sizes from SASUSER for benchmarking on a variety of straightforward tasks Benchmarking guidelines are detailed Include only essential code Replication Realistic conditions 6
Chapter 20: Controlling Memory Usage STAT 541 Chapter 20: Controlling Memory Usage ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina 7
Page Size and Buffers SAS copies data a “page” at a time to a buffer in memory Observations are loaded into the PDV (Program Data Vector) one at a time, processed, then read to an output buffer When the output buffer is full, its contents are written to an output SAS data set. I/O is measured when input data is copied to the input buffer and when output buffer contents are written to the external data set. 8
Page Size and Buffers We could reduce the number of I/O operations (or swaps) by increasing the page (or buffer) size, or by increasing the number of buffers (some systems allow only a single buffer) PROC CONTENTS can print the page size Use BUFSIZE and BUFNO options to change the page size and # of buffers Obviously, such changes should not be made without an understanding of system defaults etc 9
Page Size and Buffers Example proc contents data=stat541.meddb; run; data meddb; set stat541.meddb; data meddb (bufsize=6144 bufno=2); 10
SASFILE The SASFILE statement holds the data set in memory. Useful when The data will be used for multiple data/proc steps Sufficient real memory is available A part of the data can be processed separately Be aware of unintended consequences when not enough memory is available. 11