So it turns out that it is not possible to place a SAS lock on a table referenced via the Metadata Libname Engine:

WARNING: LOCK is not supported in MLE.

To circumvent this issue, one approach is to assign a libref directly. The following macro takes a libref (placed in the lib= keyword parameter) and queries the metadata for a physical path (placed in macro variable specified in the outvar= keyword parameter).

Note that not all librefs have an underlying directory (eg database tables).

%macro get_path_from_metalibref(lib=,outvar=filepath);
   data _null_;
      putlog “NOTE: Getting physical path for &lib library”;
      length lib_uri up_uri filepath $256;
      call missing (of _all_);
      /* get URI for the particular library */
      rc1=metadata_getnobj(“omsobj:[email protected] =’&lib'”,1,lib_uri);
      put rc1= lib_uri= ;
      /* get first object of the UsingPackages association (assumed to be Path) */
      rc2=metadata_getnasn(lib_uri,’UsingPackages’,1,up_uri);
      put rc2= up_uri= ;
      /* get the DirectoryName attribute of the previous object */
      rc3=metadata_getattr(up_uri,’DirectoryName’,filepath);
      put rc3= filepath=;
      call symputx(“&outvar”,filepath,’g’);
   run;
%mend;