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