Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mm_getauthinfo.sas
Go to the documentation of this file.
1/**
2 @file mm_getauthinfo.sas
3 @brief Extracts authentication info for each user in metadata
4 @details
5 Usage:
6
7 %mm_getauthinfo(outds=auths)
8
9
10 @param [in] mdebug= (0) Set to 1 to enable DEBUG messages and preserve outputs
11 @param [out] outds= (mm_getauthinfo) The output dataset to create
12
13 <h4> SAS Macros </h4>
14 @li mf_getuniquefileref.sas
15 @li mf_getuniquename.sas
16 @li mm_getdetails.sas
17 @li mm_getobjects.sas
18
19
20 @version 9.4
21 @author Allan Bowe
22
23**/
24
25%macro mm_getauthinfo(outds=mm_getauthinfo
26 ,mdebug=0
27)/*/STORE SOURCE*/;
28%local prefix fileref;
29%let prefix=%substr(%mf_getuniquename(),1,25);
30
31%mm_getobjects(type=Login,outds=&prefix.0)
32
33%local fileref;
34%let fileref=%mf_getuniquefileref();
35
36data _null_;
37 file &fileref;
38 set &prefix.0 end=last;
39 /* run macro */
40 str=cats('%mm_getdetails(uri=',id,",outattrs=&prefix.d",_n_
41 ,",outassocs=&prefix.a",_n_,")");
42 put str;
43 /* transpose attributes */
44 str=cats("proc transpose data=&prefix.d",_n_,"(drop=type) out=&prefix.da"
45 ,_n_,"(drop=_name_);var value;id name;run;");
46 put str;
47 /* add extra info to attributes */
48 str=cats("data &prefix.da",_n_,";length login_id login_name $256; login_id="
49 ,quote(trim(id)),";set &prefix.da",_n_
50 ,";login_name=trim(subpad(name,1,256));drop name;run;");
51 put str;
52 /* add extra info to associations */
53 str=cats("data &prefix.a",_n_,";length login_id login_name $256; login_id="
54 ,quote(trim(id)),";login_name=",quote(trim(name))
55 ,";set &prefix.a",_n_,";run;");
56 put str;
57 if last then do;
58 /* collate attributes */
59 str=cats("data &prefix._logat; set &prefix.da1-&prefix.da",_n_,";run;");
60 put str;
61 /* collate associations */
62 str=cats("data &prefix._logas; set &prefix.a1-&prefix.a",_n_,";run;");
63 put str;
64 /* tidy up */
65 str=cats("proc delete data=&prefix.da1-&prefix.da",_n_,";run;");
66 put str;
67 str=cats("proc delete data=&prefix.d1-&prefix.d",_n_,";run;");
68 put str;
69 str=cats("proc delete data=&prefix.a1-&prefix.a",_n_,";run;");
70 put str;
71 end;
72run;
73
74%if &mdebug=1 %then %do;
75 data _null_;
76 infile &fileref;
77 if _n_=1 then putlog // "Now executing the following code:" //;
78 input; putlog _infile_;
79 run;
80%end;
81%inc &fileref;
82filename &fileref clear;
83
84/* get libraries */
85proc sort data=&prefix._logas(where=(assoc='Libraries')) out=&prefix._temp;
86 by login_id;
87data &prefix._temp;
88 set &prefix._temp;
89 by login_id;
90 length library_list $32767;
91 retain library_list;
92 if first.login_id then library_list=name;
93 else library_list=catx(' !! ',library_list,name);
94proc sql;
95/* get auth domain */
96create table &prefix._dom as
97 select login_id,name as domain
98 from &prefix._logas
99 where assoc='Domain';
100create unique index login_id on &prefix._dom(login_id);
101/* join it all together */
102create table &outds as
103 select a.*
104 ,c.domain
105 ,b.library_list
106 from &prefix._logat (drop=ishidden lockedby usageversion publictype) a
107 left join &prefix._temp b
108 on a.login_id=b.login_id
109 left join &prefix._dom c
110 on a.login_id=c.login_id;
111
112%if &mdebug=0 %then %do;
113 proc datasets lib=work;
114 delete &prefix:;
115 run;
116%end;
117
118
119%mend mm_getauthinfo;