BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bheinsius
Lapis Lazuli | Level 10

Hi,

 

I want to obtain my email address from SAS metadata but cannot seem to get it.

 

The problem is that I don't know who I am in my SAS session.

 

I expected &_METAUSER to provide the Person name that I could use to search the Persons metadata objects for:

3.png

 

 

but it seems that &_METAUSER provides the account that the SAS session used to identify itself to the metadata server.

 

Example:

This is me in Management Console:

7-11-2018 15-15-27.png

 

This is what &_metauser says when I %put it on my SASApp workspace server (Linux):

 

22 %put &=_metauser;
_METAUSER=bart.heinsius.sas-b

 

This is what &_metauser says when I %put it on my SASConnect workspace server (Windows):

 

22 %put &=_metauser;
_METAUSER=Bart.Heinsius-B@EUROPE

 

I thought that maybe they were login accounts so I could search metadata for them, but they are not:

2.png

 

 

Any ideas on how I can find my Person name?

 

Bart Heinsius

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Maybe something like:

 

data _null_;
   length 
      userUri mailUri eMail $ 250
   ;
   User = "&_MetaUser";

   if index(User, '@') then do;
      User = lowcase(cats(scan(User, 2, '@'), '\', scan(User, 1, '@')));
   end;
   

   searchUri = cats("omsobj:Person?Person[Logins/Login[@UserId = '", User ,"']]");
   userUri = "";
   rc = metadata_getnobj(searchUri, 1, userUri);

   if rc = 1 then do;
      mailUri = "";
      rc = metadata_getnasn(userUri, 'EMailAddresses', 1, mailUri);
      
      if rc = 1 then do;
         rc = metadata_getattr(mailUri, 'Address', eMail);
      end;

   end;
/*
   shorter if you see a chance to get the user's name as saved in the Person-Meta-object,
   check &_ClientUserID!!
 
   UriMail = "";
   UriMail = cats("omsobj:Email?Email[@EmailType contains 'dienstlich']",
               "[Persons/Person[Logins/Login[@UserId = '&_ClientUserId.']]");

   eMail = "";
   rc = metadata_getattr(UriMail, 'Address', eMail);
*/
   put _all_;
run;

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

Maybe something like:

 

data _null_;
   length 
      userUri mailUri eMail $ 250
   ;
   User = "&_MetaUser";

   if index(User, '@') then do;
      User = lowcase(cats(scan(User, 2, '@'), '\', scan(User, 1, '@')));
   end;
   

   searchUri = cats("omsobj:Person?Person[Logins/Login[@UserId = '", User ,"']]");
   userUri = "";
   rc = metadata_getnobj(searchUri, 1, userUri);

   if rc = 1 then do;
      mailUri = "";
      rc = metadata_getnasn(userUri, 'EMailAddresses', 1, mailUri);
      
      if rc = 1 then do;
         rc = metadata_getattr(mailUri, 'Address', eMail);
      end;

   end;
/*
   shorter if you see a chance to get the user's name as saved in the Person-Meta-object,
   check &_ClientUserID!!
 
   UriMail = "";
   UriMail = cats("omsobj:Email?Email[@EmailType contains 'dienstlich']",
               "[Persons/Person[Logins/Login[@UserId = '&_ClientUserId.']]");

   eMail = "";
   rc = metadata_getattr(UriMail, 'Address', eMail);
*/
   put _all_;
run;
bheinsius
Lapis Lazuli | Level 10

Andreas,

 

Thank you but what I am really looking for is an option or macvar that I can relate 1-on-1 to the Person name, or any other attribute that the Person has. Is there no way to get the yellow value below directly from a SAS program?

 

4.png

 

-

 

 

Bart

PaulHomes
Rhodochrosite | Level 12

Hi Bart,

 

Depending on the context in which the SAS code is running you may potentially have a &_METAPERSON macro variable, containing the identity name, although I assume you have %put _all_ and not found it.

 

The &_METAUSER macro variable does look like a login user id but in mixed-case user and user@domain format instead of the low-case user and domain\user format you have in your metadata. A transformation of user@domain to domain\user and a case-insensitive search of metadata Login objects should locate the Login object for the logged in user (Person). You can then follow the association to the Person object and then another association to the one or more Email objects for that Person. You could do this using data step metadata functions like @andreas_lds suggested or use the standard SAS %MDUEXTR macro to get all user info into SAS tables to query. We also have some similar macros at https://github.com/Metacoda/idsync-utils that can extract various aspects of SAS identity metadata into SAS tables:

A join of those 2 tables (on object id) with a filter on userId with an appropriately transformed &_METAUSER should give you the email address(es) for the user. If you are doing identity sync then you might cache such a table at the same time to facilitate easy lookups.

 

Cheers
Paul

bheinsius
Lapis Lazuli | Level 10

So apparently there is no ready-made person id available in the SAS session (which sort of amazes me), apart from the metaperson that I don't have in my sas session.

So @andreas_lds' code does what @PaulHomes explains so I used it and it works like a charm.

Thank you both.

 

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 4484 views
  • 3 likes
  • 3 in conversation