Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mv_getgroups.sas
Go to the documentation of this file.
1/**
2 @file mv_getgroups.sas
3 @brief Creates a dataset with a list of viya groups
4 @details First, load the macros:
5
6 filename mc url
7 "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
8 %inc mc;
9
10 Next, execute:
11
12 %mv_getgroups(outds=work.groups)
13
14 @param [in] access_token_var= The global macro variable to contain the access token
15 @param [in] grant_type= valid values are "password" or "authorization_code" (unquoted).
16 The default is authorization_code.
17 @param [out] outds= The library.dataset to be created that contains the list of groups
18
19
20 @version VIYA V.03.04
21 @author Allan Bowe, source: https://github.com/sasjs/core
22
23 <h4> SAS Macros </h4>
24 @li mp_abort.sas
25 @li mf_getplatform.sas
26 @li mf_getuniquefileref.sas
27 @li mf_getuniquelibref.sas
28
29**/
30
31%macro mv_getgroups(access_token_var=ACCESS_TOKEN
32 ,grant_type=sas_services
33 ,outds=work.viyagroups
34 );
35%local oauth_bearer;
36%if &grant_type=detect %then %do;
37 %if %symexist(&access_token_var) %then %let grant_type=authorization_code;
38 %else %let grant_type=sas_services;
39%end;
40%if &grant_type=sas_services %then %do;
41 %let oauth_bearer=oauth_bearer=sas_services;
42 %let &access_token_var=;
43%end;
44
45%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
46 and &grant_type ne sas_services
47 )
48 ,mac=&sysmacroname
49 ,msg=%str(Invalid value for grant_type: &grant_type)
50)
51
52options noquotelenmax;
53%local base_uri; /* location of rest apis */
54%let base_uri=%mf_getplatform(VIYARESTAPI);
55
56/* fetching folder details for provided path */
57%local fname1;
58%let fname1=%mf_getuniquefileref();
59%let libref1=%mf_getuniquelibref();
60
61proc http method='GET' out=&fname1 &oauth_bearer
62 url="&base_uri/identities/groups?limit=10000";
63 headers
64 %if &grant_type=authorization_code %then %do;
65 "Authorization"="Bearer &&&access_token_var"
66 %end;
67 "Accept"="application/json";
68run;
69/*data _null_;infile &fname1;input;putlog _infile_;run;*/
70%mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
71 ,mac=&sysmacroname
72 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
73)
74libname &libref1 JSON fileref=&fname1;
75
76data &outds;
77 set &libref1..items;
78run;
79
80
81
82/* clear refs */
83filename &fname1 clear;
84libname &libref1 clear;
85
86%mend mv_getgroups;