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