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