SAS libraries that are well suited for memory-based processing have data that is
referenced or updated multiple times within a
SAS session.
Using a Work library that is memory-based is beneficial for procedures such as PROC
SORT that write multiple times to
large temporary files. To designate the Work library as memory-based, specify the
MEMLIB system option when you start SAS.
You designate a library as memory-based by using the MEMLIB option in the LIBNAME
statement. All librefs, including
a
libref to the Work
directory, must have a valid disk directory.
After the library is designated as memory-based, your SAS program needs to copy the
library from disk to memory. After processing
the library in memory, the library must be copied back to disk.
CAUTION:
Copy the
library that is in memory to disk after processing is complete.
If you do not, you
lose any changes that were made to the library. The changes are lost
when the SAS session ends
The following example shows how to use the LIBNAME statement and the PROC COPY statement
to copy a library to and from memory.
/* Set up two librefs, one to the library in memory
and the other to the SAS library on disk. The library on
disk contains dataset1, dataset2, dataset3 and dataset4. */
libname inmemory “g:\memlib” memlib;
libname ondisk “g:\disk”;
/* Copy dataset1, dataset2, dataset3, and dataset4 to memory */
proc copy in=ondisk out=inmemory;
run;
/* ...Assume dataset1 and dataset4 are updated */
/* Save the updated datasets back to disk */
proc copy in=inmemory out=ondisk;
select dataset1 dataset4;
run;
You can also copy a data set to memory by using a DATA statement, as shown in the
following example:
data ondisk.dataset1;
set inmemory.dataset1;
run;