Published on :

Unlock a SAS Dataset

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
This macro, `%di_util_unlock`, takes the name of a SAS© dataset (with its libref) as input. It first checks if the dataset exists. If so, it executes the `LOCK CLEAR` command to release any existing lock, allowing other processes or users to access it. This is an administrative operation to manage concurrent access.
Data Analysis

Type : EXTERNAL


The macro operates on a SAS dataset passed as a parameter. It does not create or read data, but modifies the lock status of an existing external dataset.

1 Code Block
MACRO
Explanation :
This block defines a macro named `di_util_unlock` that accepts a `ds` argument. Inside the macro, the `%sysfunc(exist(&ds))` function is used to check if the dataset specified by `ds` exists. If the condition is true, the `LOCK &ds CLEAR` statement is executed to lift the lock on that dataset.
Copied!
1%macro di_util_unlock(ds);
2%IF %sysfunc(exist(&ds)) %THEN %DO;
3 lock &ds clear;
4%END;
5%mend;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright (C) 2016 SAS Institute, Inc. All rights reserved.


Banner
Expert Advice
Expert
Simon
Expert SAS et fondateur.
« The %di_util_unlock macro is a vital utility for automated data pipelines, particularly in multi-user environments. In SAS, a resource lock occurs when a process or user gains exclusive access to a table, preventing others from writing to or sometimes even reading it. This macro ensures that "deadlocks"—where a table remains locked because a previous process crashed or failed to terminate properly—are cleared before your job attempts to run. »