如何获取当前用户的SAS元数据组?

时间:2017-05-17 04:32:57

标签: sas

我希望根据当前用户的元数据组成员资格设置宏变量的值(在工作区服务器的autoexec文件中)。

用户可以在多个组中,我需要能够编写逻辑,根据用户所属的“最高”组来决定变量的值(对于某些最高的定义)。

我已经研究过从SAS代码查询元数据的通用方法,但他们似乎建议执行用户应该具有管理角色,而我的用户则不会。

1 个答案:

答案 0 :(得分:1)

用户无需成为管理员即可查询元数据。他们需要具有对元数据对象的读访问权。我只是我们服务器上的用户,我可以使用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;

会认为可以调整以查找当前用户的群组。