Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mm_getgroupmembers.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Creates dataset with all members of a metadata group
4  @details
5 
6  usage:
7 
8  %mm_getgroupmembers(someGroupName
9  ,outds=work.mm_getgroupmembers
10  ,emails=YES)
11 
12  @param group metadata group for which to bring back members
13  @param outds= the dataset to create that contains the list of members
14  @param emails= set to YES to bring back email addresses
15  @param id= set to yes if passing an ID rather than a group name
16 
17  @returns outds dataset containing all members of the metadata group
18 
19  @version 9.2
20  @author Allan Bowe
21 
22 **/
23 
24 %macro mm_getgroupmembers(
25  group /* metadata group for which to bring back members */
26  ,outds=work.mm_getgroupmembers /* output dataset to contain the results */
27  ,emails=NO /* set to yes to bring back emails also */
28  ,id=NO /* set to yes if passing an ID rather than group name */
29 )/*/STORE SOURCE*/;
30 
31  data &outds ;
32  attrib uriGrp uriMem GroupId GroupName Group_or_Role MemberName MemberType
33  euri email length=$64
34  GroupDesc length=$256
35  rcGrp rcMem rc i j length=3;
36  call missing (of _all_);
37  drop uriGrp uriMem rcGrp rcMem rc i j arc ;
38 
39  i=1;
40  * Grab the URI for the first Group ;
41  %if &id=NO %then %do;
42  rcGrp=metadata_getnobj("omsobj:IdentityGroup?@Name='&group'",i,uriGrp);
43  %end;
44  %else %do;
45  rcGrp=metadata_getnobj("omsobj:IdentityGroup?@Id='&group'",i,uriGrp);
46  %end;
47  * If Group found, enter do loop ;
48  if rcGrp>0 then do;
49  call missing (rcMem,uriMem,GroupId,GroupName,Group_or_Role
50  ,MemberName,MemberType);
51  * get group info ;
52  rc = metadata_getattr(uriGrp,"Id",GroupId);
53  rc = metadata_getattr(uriGrp,"Name",GroupName);
54  rc = metadata_getattr(uriGrp,"PublicType",Group_or_Role);
55  rc = metadata_getattr(uriGrp,"Desc",GroupDesc);
56  j=1;
57  do while (metadata_getnasn(uriGrp,"MemberIdentities",j,uriMem) > 0);
58  call missing (MemberName, MemberType, email);
59  rc = metadata_getattr(uriMem,"Name",MemberName);
60  rc = metadata_getattr(uriMem,"PublicType",MemberType);
61  if membertype='User' and "&emails"='YES' then do;
62  if metadata_getnasn(uriMem,"EmailAddresses",1,euri)>0 then do;
63  arc=metadata_getattr(euri,"Address",email);
64  end;
65  end;
66  output;
67  j+1;
68  end;
69  end;
70  run;
71 
72 %mend;