www.sas.com > SAS UK > In the Know Homepage Search | Contact Us    
SAS UK Newsletter Banner SAS - The power to know(tm)  

Is there a way to reduce the processing time for frequently reused data sets?

By using the SASFILE statement in Release 8.1 and higher, you can reduce multiple open and close operations (including allocation and freeing of memory for buffers) for data set processing to just one open and close operation. The SASFILE statement also reduces I/O processing by holding the data in memory.

When the SASFILE statement executes, SAS opens the file. Then, when subsequent DATA and PROC steps execute, SAS doesn't have to open the file each time. The file remains open until a second SASFILE statement closes it, or until the program or session ends. In other words, a file opened with the SASFILE statement will remain open in memory until the end of the job or until explicitly released.

If your program consists of steps that read a SAS data set multiple times and you have an adequate amount of memory so that the entire file can be held in real memory, your program should benefit from using the SASFILE statement.

Also, the SASFILE statement is useful as a part of the program that starts a SAS server, such as SAS/SHARE server. (There is an additional ALLOCATE SASFILE command in PROC SERVER that uses different syntax than the SASFILE statement explained here.)

When a SASFILE statement opens a SAS data set, the file is opened for input processing. Once opened, the file cannot be processed by any procedure or statement that requires exclusive access to the file. For example, you cannot replace the file or do processing that requires utility mode access, such as rename its variables. However, a MODIFY statement or PROC SQL update can run on the file. For example, PROC SQL update, delete or insert statements do not require exclusive access to the data set, so they are allowed to run on a data set opened with the SASFILE statement.

When the SASFILE statement is executed, SAS checks whether the file is read-protected. If the file is read-protected, you must include the READ= password in the SASFILE statement. If the file is either write- or alter-protected, you can use a WRITE=, ALTER or PW= password.

Try the following code that uses the SASFILE statement in Releases 8.1 and 8.2. Remember to remove the SASFILE statements when you run it the second time to compare the elapsed or CPU time.

data work.big;
 array vv(10) 8;
 do key=1 to 500000;
   do i=1 to dim(vv);
      vv(i)=ranuni(1);
   end;
   output;
 end;
run;
sasfile work.big load;
proc means data=work.big; run;
proc means data=work.big; run;
sasfile work.big close;

Note: The above code has been tested using SAS 8.2 on the Windows operating system.