As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Difference between revisions of "Tips:Using the LOCK Statement for Exclusive Use of a SAS Data Set"

From sasCommunity
Jump to: navigation, search
(gardening)
(gardening)
Line 5: Line 5:
  
 
proc copy in=sashelp out=templib;
 
proc copy in=sashelp out=templib;
select orsales;
+
    select orsales;
 
run;
 
run;
  
Line 11: Line 11:
  
 
proc summary nway data=templib.orsales;
 
proc summary nway data=templib.orsales;
class Product_Line;
+
    class Product_Line;
var quantity profit;
+
    var quantity profit;
output out=summ1 sum=;
+
    output out=summ1 sum=;
 
run;
 
run;
  
Line 22: Line 22:
 
'''LOCK''' is a Base SAS statement. Although there is increased functionality with SAS/SHARE, LOCK can be used to simulate some of the capabilities of SAS/SHARE.
 
'''LOCK''' is a Base SAS statement. Although there is increased functionality with SAS/SHARE, LOCK can be used to simulate some of the capabilities of SAS/SHARE.
  
See the sample code at right for the syntax for the LOCK statement. After the first LOCK statement, you will see the following in the SAS Log:
+
See the sample code at right for the syntax for the LOCK statement. After the first LOCK statement, you will see the following in the [[SAS Log]]:
  
<br>
+
<br><i>
<i>
+
    NOTE: TEMPLIB.ORSALES.DATA is now locked for exclusive access by you.
NOTE: TEMPLIB.ORSALES.DATA is now locked for exclusive access by you.
+
</i><br><br>
</i>
+
<br><br>
+
  
 
After the second LOCK statement, with the CLEAR option, you will see the following in the SAS Log:
 
After the second LOCK statement, with the CLEAR option, you will see the following in the SAS Log:
  
<br>
+
<br><i>
<i>
+
    NOTE: TEMPLIB.ORSALES.DATA is no longer locked by you.
NOTE: TEMPLIB.ORSALES.DATA is no longer locked by you.
+
</i><br><br>
</i>
+
<br><br>
+
  
 
The LOCK statement might be just the thing that you need to ensure your privacy when processing SAS data sets on shared disk space!
 
The LOCK statement might be just the thing that you need to ensure your privacy when processing SAS data sets on shared disk space!

Revision as of 14:52, 26 October 2017

options msglevel=I;
 
libname templib "c:\temp";
 
proc copy in=sashelp out=templib;
    select orsales;
run;
 
lock templib.orsales;
 
proc summary nway data=templib.orsales;
    class Product_Line;
    var quantity profit;
    output out=summ1 sum=;
run;
 
lock templib.orsales clear;

You can use the LOCK statement to prevent other SAS programs from either reading from or writing to a SAS data set that your program needs until you release the lock. This can be handy in cases where multiple programmers have access to SAS data sets residing on shared disk space; such as can be found on network drives, Windows servers, UNIX servers, etc. Using the LOCK statement can guarantee that you have exclusive control of a SAS data set for the time period when you need it

LOCK is a Base SAS statement. Although there is increased functionality with SAS/SHARE, LOCK can be used to simulate some of the capabilities of SAS/SHARE.

See the sample code at right for the syntax for the LOCK statement. After the first LOCK statement, you will see the following in the SAS Log:


   NOTE: TEMPLIB.ORSALES.DATA is now locked for exclusive access by you.



After the second LOCK statement, with the CLEAR option, you will see the following in the SAS Log:


   NOTE: TEMPLIB.ORSALES.DATA is no longer locked by you.



The LOCK statement might be just the thing that you need to ensure your privacy when processing SAS data sets on shared disk space!


Submitted by Michael A. Raithel, The man who wrote the book on performance. Contact me at my Discussion Page.