Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mm_getgroups.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Creates dataset with all groups or just those for a particular user
4 @details Provide a metadata user to get groups for just that user, or leave
5 blank to return all groups.
6 Usage:
7
8 - all groups: `%mm_getGroups()`
9
10 - all groups for a particular user: `%mm_getgroups(user=&sysuserid)`
11
12 @param [in] user= the metadata user to return groups for. Leave blank for all
13 groups.
14 @param [in] repo= the metadata repository that contains the user/group
15 information
16 @param [in] mDebug= set to 1 to show debug messages in the log
17 @param [out] outds= the dataset to create that contains the list of groups
18
19 @returns outds dataset containing all groups in a column named "metagroup"
20 - groupuri
21 - groupname
22 - groupdesc
23
24 @version 9.2
25 @author Allan Bowe
26
27**/
28
29%macro mm_getGroups(
30 user=
31 ,outds=work.mm_getGroups
32 ,repo=foundation
33 ,mDebug=0
34)/*/STORE SOURCE*/;
35
36%local mD oldrepo;
37%let oldrepo=%sysfunc(getoption(metarepository));
38%if &mDebug=1 %then %let mD=;
39%else %let mD=%str(*);
40%&mD.put Executing mm_getGroups.sas;
41%&mD.put _local_;
42
43/* on some sites, user / group info is in a different metadata repo to the
44 default */
45%if &oldrepo ne &repo %then %do;
46 options metarepository=&repo;
47%end;
48
49%if %length(&user)=0 %then %do;
50 data &outds (keep=groupuri groupname groupdesc);
51 length groupuri groupname groupdesc group_or_role $256;
52 call missing(of _all_);
53 i+1;
54 do while
55 (metadata_getnobj("omsobj:IdentityGroup?@Id contains '.'",i,groupuri)>0);
56 rc=metadata_getattr(groupuri, "Name", groupname);
57 rc=metadata_getattr(groupuri, "Desc", groupdesc);
58 rc=metadata_getattr(groupuri,"PublicType",group_or_role);
59 if Group_or_Role = 'UserGroup' then output;
60 i+1;
61 end;
62 run;
63%end;
64%else %do;
65 data &outds (keep=groupuri groupname groupdesc);
66 length uri groupuri groupname groupdesc group_or_role $256;
67 call missing(of _all_);
68 rc=metadata_getnobj("omsobj:Person?@Name='&user'",1,uri);
69 if rc<=0 then do;
70 putlog "%str(WARN)ING: rc=" rc "&user not found "
71 ", or there was an issue reading the repository.";
72 stop;
73 end;
74 a=1;
75 grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
76 if grpassn in (-3,-4) then do;
77 putlog "%str(WARN)ING: No metadata groups found for &user";
78 output;
79 end;
80 else do while (grpassn > 0);
81 rc=metadata_getattr(groupuri, "Name", groupname);
82 rc=metadata_getattr(groupuri, "Desc", groupdesc);
83 a+1;
84 rc=metadata_getattr(groupuri,"PublicType",group_or_role);
85 if Group_or_Role = 'UserGroup' then output;
86 grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
87 end;
88 run;
89%end;
90
91%if &oldrepo ne &repo %then %do;
92 options metarepository=&oldrepo;
93%end;
94
95%mend mm_getGroups;