SAS Programming
Memory Based Libraries: Part III: Using a Memory-Based Library as a SAS File Cache
A SAS file cache improves performance in SAS programs that make multiple passes of the data. SAS file caching improves performance in the following situations:
- Repeated Read operations of a file while other files are being written. Writing to a file clears the Windows file system (NTFS) cache.
- Repeated Read operations of a file when Scatter Gather I/O is active. Scatter Gather I/O operates outside the NTFS cache. Without the SAS file cache, there is no data cache and all Read operations access the disk.
To use memory as a SAS file cache, specify the MEMCACHE system option when you start SAS or when you submit an OPTIONS statement. MEMCACHE value of 4 allows SAS to use memory to cache all files. A MEMCACHE value of 1 has current files in memory to be cached.
A MEMCACHE system option in the OPTIONS statement gives control which data sets use the SAS file cache, as shown in the following example.
/* Example of controlling cached files with the options statement */
/* Assume cachelib contains 2 data sets, dsA and dsB. */
/* dsA and dsB are large enough that they cannot fit */
/* in the cache together. dsA is read multiple times, ideal for */
/* caching. dsB is accessed only once, so caching is of no */
/* benefit. memcache option, allows dsA to be cached only */
libname cachelib "e:\tmp";
/* Turn on full caching */
options memcache = 4;
/* Read dsA and place the data in the cache. */
data _null_;
set cachelib.dsA;
run;
/* Change memcache setting to use the cache only for files that */
/* already exist in the cache. */
options memcache = 1;
/* Data from dsA will come from the cache and dsB will not be */
/* cached. */
proc sort data=cachelib.dsA out=cachelib.dsB;
by X;
run;
/* Other access of dsA... */
/* All use of the cache can be ended with a memcache system */
/* option value of 0. */
options memcache = 0;
/* Neither dsA nor dsB will access the cache. */
proc sort data=cachelib.dsA out=cachelib.dsB;
by X;
run;