[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2980
  • Last Modified:

SAS locks

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
sanofi-aventis
Asked:
sanofi-aventis
  • 3
  • 2
  • 2
  • +1
3 Solutions
 
d507201Database Marketing ConsultantCommented:
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
 
theartfuldazzlerCommented:
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
 
d507201Database Marketing ConsultantCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sanofi-aventisAuthor Commented:
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
 
Aloysius LowCommented:
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
 
theartfuldazzlerCommented:
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
 
sanofi-aventisAuthor Commented:
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
 
sanofi-aventisAuthor Commented:
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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now