Sakthi
Sakthi

Reputation: 45

Credentials for a sas metadata library-User ID

I have a situation here where I need the User ID of the SAS Metadata Libraries. I do not want to list out the users who access the Metadata. So, Fetch user id from SAS metadata server is not the solution for my query.

Please help

Upvotes: 1

Views: 896

Answers (1)

Allan Bowe
Allan Bowe

Reputation: 12691

SAS code to obtain the credentials (from metadata) for an ODBC library engine might look like the following:

%let libref=MYLIB;
/* get liburi */
data _null_;
  length lib_uri $256;
  call missing (of _all_);
  /* get URI for the particular library */
  rc=metadata_getnobj("omsobj:SASLibrary?@Libref ='&libref'",1,lib_uri);
  call symputx("liburi",lib_uri,'l');
run;
/* query for credentials */
data _null_;
  length connx_uri conprop_uri value datasource up_uri schema $256.;
  call missing (of _all_);
  /* get source connection ID */
  rc=metadata_getnasn("&liburi",'LibraryConnection',1,connx_uri);
  /* get connection properties */
  i=0;
  do until (rc2<0);
    i+1;
    rc2=metadata_getnasn(connx_uri,'Properties',i,conprop_uri);
    rc3=metadata_getattr(conprop_uri,'Name',value);
    if value='Connection.ODBC.Property.DATASRC.Name.xmlKey.txt' then do;
       rc4=metadata_getattr(conprop_uri,'DefaultValue',datasource);
       rc2=-1;
    end;
  end;
  /* get SCHEMA */
  rc6=metadata_getnasn("&liburi",'UsingPackages',1,up_uri);
  rc7=metadata_getattr(up_uri,'SchemaName',schema);
  call symputx('SQL_schema',schema,'l');
  call symputx('SQL_dsn',datasource,'l');
run;

libname &libref ODBC DATASRC=&sql_dsn SCHEMA=&sql_schema;

A macro which will generate a libname statement for other library types is available here.

Upvotes: 0

Related Questions