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