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, source: https://github.com/sasjs/core
34 
35  <h4> SAS Macros </h4>
36  @li mp_abort.sas
37  @li mf_getplatform.sas
38  @li mf_getuniquefileref.sas
39  @li mf_getuniquelibref.sas
40 
41 **/
42 
43 %macro mv_getgroupmembers(group
44  ,access_token_var=ACCESS_TOKEN
45  ,grant_type=sas_services
46  ,outds=work.viyagroupmembers
47  );
48 %local oauth_bearer;
49 %if &grant_type=detect %then %do;
50  %if %symexist(&access_token_var) %then %let grant_type=authorization_code;
51  %else %let grant_type=sas_services;
52 %end;
53 %if &grant_type=sas_services %then %do;
54  %let oauth_bearer=oauth_bearer=sas_services;
55  %let &access_token_var=;
56 %end;
57 %put &sysmacroname: grant_type=&grant_type;
58 %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
59  and &grant_type ne sas_services
60  )
61  ,mac=&sysmacroname
62  ,msg=%str(Invalid value for grant_type: &grant_type)
63 )
64 
65 options noquotelenmax;
66 
67 %local base_uri; /* location of rest apis */
68 %let base_uri=%mf_getplatform(VIYARESTAPI);
69 
70 /* fetching folder details for provided path */
71 %local fname1;
72 %let fname1=%mf_getuniquefileref();
73 proc http method='GET' out=&fname1 &oauth_bearer
74  url="&base_uri/identities/groups/&group/members?limit=10000";
75  headers
76  %if &grant_type=authorization_code %then %do;
77  "Authorization"="Bearer &&&access_token_var"
78  %end;
79  "Accept"="application/json";
80 run;
81 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
82 %if &SYS_PROCHTTP_STATUS_CODE=404 %then %do;
83  %put NOTE: Group &group not found!!;
84  data &outds;
85  length id name $43;
86  call missing(of _all_);
87  run;
88 %end;
89 %else %do;
90  %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
91  ,mac=&sysmacroname
92  ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
93  )
94  %let libref1=%mf_getuniquelibref();
95  libname &libref1 JSON fileref=&fname1;
96  data &outds;
97  length id name $43;
98  set &libref1..items;
99  run;
100  libname &libref1 clear;
101 %end;
102 
103 /* clear refs */
104 filename &fname1 clear;
105 
106 %mend;