Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mv_getgroupmembers.sas
Go to the documentation of this file.
1 /**
2  @file mv_getgroupmembers.sas
3  @brief Creates a dataset with a list of group members
4  @details First, be sure you have an access token (which requires an app token).
5 
6  Using the macros here:
7 
8  filename mc url
9  "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
10  %inc mc;
11 
12  Now we can run the macro!
13 
14  %mv_getgroupmembers(All Users)
15 
16  outputs:
17 
18  ordinal_root num,
19  ordinal_items num,
20  version num,
21  id char(43),
22  name char(43),
23  providerId char(5),
24  implicit num
25 
26  @param access_token_var= The global macro variable to contain the access token
27  @param grant_type= valid values are "password" or "authorization_code" (unquoted).
28  The default is authorization_code.
29  @param outds= The library.dataset to be created that contains the list of groups
30 
31 
32  @version VIYA V.03.04
33  @author Allan Bowe
34  @source https://github.com/sasjs/core
35 
36  <h4> Dependencies </h4>
37  @li mp_abort.sas
38  @li mf_getplatform.sas
39  @li mf_getuniquefileref.sas
40  @li mf_getuniquelibref.sas
41 
42 **/
43 
44 %macro mv_getgroupmembers(group
45  ,access_token_var=ACCESS_TOKEN
46  ,grant_type=sas_services
47  ,outds=work.viyagroupmembers
48  );
49 %local oauth_bearer;
50 %if &grant_type=detect %then %do;
51  %if %symexist(&access_token_var) %then %let grant_type=authorization_code;
52  %else %let grant_type=sas_services;
53 %end;
54 %if &grant_type=sas_services %then %do;
55  %let oauth_bearer=oauth_bearer=sas_services;
56  %let &access_token_var=;
57 %end;
58 %put &sysmacroname: grant_type=&grant_type;
59 %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
60  and &grant_type ne sas_services
61  )
62  ,mac=&sysmacroname
63  ,msg=%str(Invalid value for grant_type: &grant_type)
64 )
65 
66 options noquotelenmax;
67 
68 %local base_uri; /* location of rest apis */
69 %let base_uri=%mf_getplatform(VIYARESTAPI);
70 
71 /* fetching folder details for provided path */
72 %local fname1;
73 %let fname1=%mf_getuniquefileref();
74 proc http method='GET' out=&fname1 &oauth_bearer
75  url="&base_uri/identities/groups/&group/members?limit=10000";
76  headers
77  %if &grant_type=authorization_code %then %do;
78  "Authorization"="Bearer &&&access_token_var"
79  %end;
80  "Accept"="application/json";
81 run;
82 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
83 %if &SYS_PROCHTTP_STATUS_CODE=404 %then %do;
84  %put NOTE: Group &group not found!!;
85  data &outds;
86  length id name $43;
87  call missing(of _all_);
88  run;
89 %end;
90 %else %do;
91  %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
92  ,mac=&sysmacroname
93  ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
94  )
95  %let libref1=%mf_getuniquelibref();
96  libname &libref1 JSON fileref=&fname1;
97  data &outds;
98  length id name $43;
99  set &libref1..items;
100  run;
101  libname &libref1 clear;
102 %end;
103 
104 /* clear refs */
105 filename &fname1 clear;
106 
107 %mend;