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