Solved

SAS locks

Posted on 2011-09-26
8
2,795 Views
Last Modified: 2013-11-16
SAS 9.2 ts2m3.
Windows XP SP3
AIX 6.1

I am trying to understand the locking mechanism in SAS. We have a problem with our batch updates failing if a user is querying a dataset while we are trying to reload it. I would like to identify the lock, send an email and loop instead of having my process fail.

I tried this test and get unexpected results.
1) Start PCSAS
2) Connect to my SAS server on an AIX box.
3) Create a libname to the server.
4) Lock my dataset successfully. Lock libname.dataset;  From the log: "NOTE: MLQ_WKL.DAILYSALES.DATA is now locked for exclusive access by you."

5) Create a second PCSAS instance
6) Connect to the same AIX box.
7) Create the same libname as above.
8) Test the lock. Lock libname.dataset list; This returns the message "NOTE: MLQ_WKL.DAILYSALES.DATA is not locked or in use by you or any other users.


If I try to open the dataset in SAS Explorer I get the message below.

Why do I get the message in #8? And can I query SAS successfully for a lock to prevent my process from failing?

Sincerely,
T-Bone SAS message example
0
Comment
Question by:sanofi-aventis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 7

Accepted Solution

by:
d507201 earned 200 total points
ID: 36599429
I've never seen the lock function, and it's not in the 9.1 onl-line documentation's list of functions.  So I can't comment on what's going on there.  

I do know that unlike a true RDBMS, SAS applies file-level locking during update activity.  Go to the onl-line documentation and search for 'locking'... lots of useful hits.  To allow reading while writing, you need SAS/SHARE.  It lets SAS to apply record-level locking during updates.

To test if a dataset is locked, use the OPEN and CLOSE functions.  I haven't tested it, but I'm pretty sure that the OPEN function will fail if a dataset is locked.  So try to open the dataset and if the return code is zero then the open failed and you can send an email. and then abort the job  Non-zero means it worked--then CLOSE it and continue processing.

Something like this--

%MACRO TEST_IF_LOCKED(_datasetName);
%let dsid=%sysfunc(open(&_datasetName,i));
%if (&dsid = 0) %then %do;
  ** send email. ;
  abort;
%end;
%else %do;
  %close(&dsid);
%end;
%MEND;
0
 
LVL 11

Assisted Solution

by:theartfuldazzler
theartfuldazzler earned 200 total points
ID: 36599469
Hi

I would look to use the SYSLCKRC macro variable...  but the best is to look at the following link:

http://www.lexjansen.com/pharmasug/2005/posters/po33.pdf

Regards

D
0
 
LVL 7

Expert Comment

by:d507201
ID: 36599715
Very nice solution.  I'm always pleasantly surprised at the willingness of the folks at d-Wise to share their tips and clues.

I'd say that testing availability after opening and closing the dataset is maybe a bit much.  But if there's a chance of a timing error, I'd just put a 1-second SLEEP function immediately after the CLOSE function and not deal with locking and unlocking the dataset.  I use the sleep function quite often when I'm concerned about timing.

"Since the DATA step did some preliminary checking, it is likely that the lock statement will now succeed. However, due to split-second timing it is still possible that the lock statement will fail."

0
 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

 
LVL 2

Author Comment

by:sanofi-aventis
ID: 36600128
Thanks guys. I've google this solution myself. I understand the concept of trying a file level open prior to using the file. I do not consider this querying SAS for a lock status. The Lock statement seems to be OK. Even though I have to query my log file to get the result, it does give me the process id that has it locked. I'm surprised the Proc Dataset, or one of the other procedures or even the Dictionary views, does not have an option to return the lock status.

At this time, I don't even plan to lock the dataset prior to using it, I just want to know if someone has it locked prior to truncating it and reloading.

and still not sure why the second PCSAS session returns the message "NOTE: MLQ_WKL.DAILYSALES.DATA is not locked or in use by you or any other users.

when I cannot open the dataset in that session's SAS Explorer. I get the message in the picture above.
0
 
LVL 14

Assisted Solution

by:Aloysius Low
Aloysius Low earned 100 total points
ID: 36647187
if it's PCSAS you are talking about (vs connecting to the same SAS instance on the server), a possible explanation is because it's by a different SAS instance, hence the lock status is not recognised? but when you try to open the dataset, it tries to get the dataset locked but only to find out that it was actually already locked...

i stand corrected here - i'm just speculating, making sense of what has happened...
0
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 36707699
Hi T-Bone

I must admit - I don't know AIX.

I have done this on a Windows server using www.sysinternals.com commands such as handle.exe, processExplorer and pslist.  In theory there are similar commands in Unix - but you would need to post this question (or a related one) on the IBM AIX UNIX Zone.

Despite my lack of AIX knowlegde, I did some more googling, and came across this link:
http://stackoverflow.com/questions/688343/reference-for-proper-handling-of-pid-file-on-unix

In theory, one would just need to find the PID file (I would assume it sits in the same directory as the SAS dataset), read in the PID file as text, and get the process id number that way?

I have no way to test this - if you gon't come right - try this question on the AIX Zone.

D
0
 
LVL 2

Author Comment

by:sanofi-aventis
ID: 36709376
All,

Thank you for your comments. But neither get me any further than assumptions already attained.

You would think that if the engine allows locks and can give a message like in the picture above that this information would be available to the programmer/analyst other than just an error code when trying to access the resource.

I will keep this question open for now.

Sincerely,
T-Bone
0
 
LVL 2

Author Closing Comment

by:sanofi-aventis
ID: 36815937
Thanks all.
You can lock files in SAS.
You cannot passively identify if there is a lock on a dataset.
Only by trying to lock it and querying the SYSLCKRC macro variable will you know if you can have a lock or not.
I will need to use the operating system to know who has it locked. For Unix I am going to try the fuser & ps command to get the users id. fuser for the pid then ps for the user id that has it closed.
I still need to figure out how to get the email name from the users id.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question