Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
ms_creategroup.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Creates a group on SASjs Server
4 @details Creates a group on SASjs Server with the following attributes:
5
6 @li name
7 @li description
8 @li isActive
9
10 Examples:
11
12 %ms_creategroup(mynewgroup)
13
14 %ms_creategroup(mynewergroup, desc=The group description)
15
16 @param [in] groupname The group name to create. No spaces or special chars.
17 @param [in] desc= (0) If no description provided, group name will be used.
18 @param [in] isactive= (true) Set to false to create an inactive group.
19 @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
20 @param [out] outds= (work.ms_creategroup) This output dataset will contain the
21 values from the JSON response (such as the id of the new group)
22|DESCRIPTION:$1.|GROUPID:best.|ISACTIVE:best.|NAME:$11.|
23|---|---|---|---|
24|`The group description`|`2 `|`1 `|`mynewergroup `|
25
26
27
28 <h4> SAS Macros </h4>
29 @li mf_getuniquefileref.sas
30 @li mf_getuniquelibref.sas
31 @li mp_abort.sas
32
33 <h4> Related Files </h4>
34 @li ms_creategroup.test.sas
35 @li ms_getgroups.sas
36
37**/
38
39%macro ms_creategroup(groupname
40 ,desc=0
41 ,isactive=true
42 ,outds=work.ms_creategroup
43 ,mdebug=0
44 );
45
46%mp_abort(
47 iftrue=(&syscc ne 0)
48 ,mac=ms_creategroup.sas
49 ,msg=%str(syscc=&syscc on macro entry)
50)
51
52%local fref0 fref1 fref2 libref optval rc msg;
53%let fref0=%mf_getuniquefileref();
54%let fref1=%mf_getuniquefileref();
55%let fref2=%mf_getuniquefileref();
56%let libref=%mf_getuniquelibref();
57
58/* avoid sending bom marker to API */
59%let optval=%sysfunc(getoption(bomfile));
60options nobomfile;
61
62data _null_;
63 file &fref0 termstr=crlf;
64 name=quote(cats(symget('groupname')));
65 description=quote(cats(symget('desc')));
66 if cats(description)='"0"' then description=name;
67 isactive=symget('isactive');
68%if &mdebug=1 %then %do;
69 putlog _all_;
70%end;
71
72 put '{'@;
73 put '"name":' name @;
74 put ',"description":' description @;
75 put ',"isActive":' isactive @;
76 put '}';
77run;
78
79data _null_;
80 file &fref1 lrecl=1000;
81 infile "&_sasjs_tokenfile" lrecl=1000;
82 input;
83 if _n_=1 then do;
84 put "Content-Type: application/json";
85 put "accept: application/json";
86 end;
87 put _infile_;
88run;
89
90%if &mdebug=1 %then %do;
91 data _null_;
92 infile &fref0;
93 input;
94 put _infile_;
95 data _null_;
96 infile &fref1;
97 input;
98 put _infile_;
99 run;
100%end;
101
102proc http method='POST' in=&fref0 headerin=&fref1 out=&fref2
103 url="&_sasjs_apiserverurl/SASjsApi/group";
104%if &mdebug=1 %then %do;
105 debug level=1;
106%end;
107run;
108
109%mp_abort(
110 iftrue=(&syscc ne 0)
111 ,mac=ms_creategroup.sas
112 ,msg=%str(Issue submitting query to SASjsApi/group)
113)
114
115libname &libref JSON fileref=&fref2;
116
117data &outds;
118 set &libref..root;
119 drop ordinal_root;
120%if &mdebug=1 %then %do;
121 putlog _all_;
122%end;
123run;
124
125
126%mp_abort(
127 iftrue=(&syscc ne 0)
128 ,mac=ms_creategroup.sas
129 ,msg=%str(Issue reading response JSON)
130)
131
132/* reset options */
133options &optval;
134
135%if &mdebug=0 %then %do;
136 filename &fref0 clear;
137 filename &fref1 clear;
138 filename &fref2 clear;
139 libname &libref clear;
140%end;
141%else %do;
142 data _null_;
143 infile &fref2;
144 input;
145 putlog _infile_;
146 run;
147%end;
148
149%mend ms_creategroup;