简体   繁体   中英

How can I get the SAS Metadata groups of the current user?

I wish to set the value of a macro variable (in the autoexec file of a workspace server) based on the current user's metadata group membership.

Users can be in more than one group, and I need to be able to write logic that decides the variable's value based on the "highest" group of which the user is a member (for some definition of highest).

I have looked at generic methods for querying metadata from SAS code, but they seem to suggest the executing user should have an administrative role, and my users won't.

Users do not need to be admins in order to query metadata. They would need to have read access to the metadata objects. I'm just a user on our server, and I can get a list of all users and their associated groups, using an adaption of http://support.sas.com/kb/30/682.html :

data users_grps (keep=name group email);
   length uri name groupuri group emailuri email $256 ;

   call missing(uri, name, groupuri, group, emailuri, email) ;    

   /* Get URI of first person */
   n=1; 
   nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
   if nobj=0 then put 'No Persons available.';
   do while (nobj > 0);
      call missing(name, groupuri, group, emailuri, email) ;    

      /* Retrieve the current persons name. */
      rc=metadata_getattr(uri, "Name", Name);

      /* get the persons email address (only first one)*/
      rc2=metadata_getnasn(uri,"EmailAddresses",1,emailURI) ;
      rc3=metadata_getattr(emailuri, "Address", email);

      /* Get the group association information for the current person. */
      a=1;
      rcgrp=metadata_getnasn(uri,"IdentityGroups",a,groupuri);

         /* If this person does not belong to any groups, set their group */
         /* variable to 'No groups' and output the name. */
      if rcgrp in (-3,-4) then do;
         group="No groups";
         output;
      end;

      /* If the person belongs to any groups, loop through the list */
      /* and retrieve the name of each group, outputting each on a */
      /* separate record. */
      else do while (rcgrp > 0);
         rc4=metadata_getattr(groupuri, "Name", group);
         a+1;
         output;
         rcgrp=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
      end;

      /* Get URI of next person. */
      n+1;
      nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
   end;

run;

Would think that could be adapted to look up the groups of the current user.

This macro will give you either all groups, or the direct-group memberships of a specific user:

https://core.sasjs.io/mm__getgroups_8sas.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM