69%macro mv_createjob(path=
71 ,desc=Created by the mv_createjob.sas macro
74 ,access_token_var=ACCESS_TOKEN
75 ,grant_type=sas_services
79 ,addjesbeginendmacros=
false
82%
if &grant_type=detect %then %
do;
83 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
84 %
else %let grant_type=sas_services;
86%
if &grant_type=sas_services %then %
do;
87 %let oauth_bearer=oauth_bearer=sas_services;
88 %let &access_token_var=;
92%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
93 and &grant_type ne sas_services
96 ,msg=%str(Invalid value
for grant_type: &grant_type)
98%mp_abort(iftrue=(%mf_isblank(&path)=1)
100 ,msg=%str(path value must be provided)
102%mp_abort(iftrue=(%length(&path)=1)
104 ,msg=%str(path value must be provided)
106%mp_abort(iftrue=(%mf_isblank(&name)=1)
108 ,msg=%str(name value must be provided)
111options noquotelenmax;
114%
if "%substr(&path,%length(&path),1)" =
"/" %then
115 %let path=%substr(&path,1,%length(&path)-1);
118%put &sysmacroname: Path &path being checked / created;
119%mv_createfolder(path=&path)
122%let base_uri=%mf_getplatform(VIYARESTAPI);
126%let fname1=%mf_getuniquefileref();
127proc http method=
'GET' out=&fname1 &oauth_bearer
128 url=
"&base_uri/folders/folders/@item?path=&path";
129%
if &grant_type=authorization_code %then %
do;
130 headers
"Authorization"=
"Bearer &&&access_token_var";
140%mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
142 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
147%let libref1=%mf_getuniquelibref();
148libname &libref1 JSON fileref=&fname1;
152 if rel=
'members' then call symputx(
'membercheck',quote(
"&base_uri"!!trim(href)),
'l');
153 else if rel=
'self' then call symputx(
'parentFolderUri',href,
'l');
157 call symputx(
'folderid',
id,
'l');
160%let fname2=%mf_getuniquefileref();
161proc http method=
'GET'
164 url=%unquote(%superq(membercheck));
166 %
if &grant_type=authorization_code %then %
do;
167 "Authorization"=
"Bearer &&&access_token_var"
169 'Accept'=
'application/vnd.sas.collection+json'
170 'Accept-Language'=
'string';
171%
if &debug=1 %then %
do;
176%mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
178 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
181%
if %upcase(&replace)=YES %then %
do;
182 %mv_deletejes(path=&path, name=&name)
187 %let libref2=%mf_getuniquelibref();
188 libname &libref2 JSON fileref=&fname2;
189 %local exists; %let exists=0;
192 if contenttype=
'jobDefinition' and upcase(name)=
"%upcase(&name)" then
193 call symputx(
'exists',1,
'l');
195 %mp_abort(iftrue=(&exists=1)
197 ,msg=%str(Job &name already exists in &path)
199 libname &libref2 clear;
204%let fname3=%mf_getuniquefileref();
206 file &fname3 TERMSTR=
' ';
207 length
string $32767;
208 string=cats(
'{"version": 0,"name":"'
210 ,
'","type":"Compute","parameters":['
211%
if &addjesbeginendmacros ne 0 %then %
do;
212 ,
'{"name":"_addjesbeginendmacros"'
213 ,
',"type":"CHARACTER","defaultValue":"'
214 ,
"&addjesbeginendmacros"
219 context=quote(cats(symget(
'contextname')));
220 if context ne
'""' then
do;
223 ,
'{"version": 1,"name": "_contextName","defaultValue":'
224 ,context,
',"type":"CHARACTER","label":"Context Name","required": false}'
227 string=cats(
string,
'],"code":"');
233%local x fref freflist;
234%let freflist= &precode &code ;
235%
do x=1 %to %sysfunc(countw(&freflist));
236 %let fref=%scan(&freflist,&x);
237 %put &sysmacroname: adding &fref;
239 length filein 8 fileid 8;
240 filein = fopen(
"&fref",
"I",1,
"B");
241 fileid = fopen(
"&fname3",
"A",1,
"B");
243 do while(fread(filein)=0);
244 rc = fget(filein,rec,1);
246 rc =fput(fileid,
'\');rc =fwrite(fileid);
247 rc =fput(fileid,
'"');rc =fwrite(fileid);
249 else if rec=
'0A'x then
do;
250 rc =fput(fileid,
'\');rc =fwrite(fileid);
251 rc =fput(fileid,
'n');rc =fwrite(fileid);
253 else if rec=
'0D'x then
do;
254 rc =fput(fileid,
'\');rc =fwrite(fileid);
255 rc =fput(fileid,
'r');rc =fwrite(fileid);
257 else if rec=
'09'x then
do;
258 rc =fput(fileid,
'\');rc =fwrite(fileid);
259 rc =fput(fileid,
't');rc =fwrite(fileid);
261 else if rec=
'5C'x then
do;
262 rc =fput(fileid,
'\');rc =fwrite(fileid);
263 rc =fput(fileid,
'\');rc =fwrite(fileid);
265 else if rec=
'01'x then
do;
266 rc =fput(fileid,
'\');rc =fwrite(fileid);
267 rc =fput(fileid,
'u');rc =fwrite(fileid);
268 rc =fput(fileid,
'0');rc =fwrite(fileid);
269 rc =fput(fileid,
'0');rc =fwrite(fileid);
270 rc =fput(fileid,
'0');rc =fwrite(fileid);
271 rc =fput(fileid,
'1');rc =fwrite(fileid);
273 else if rec=
'07'x then
do;
274 rc =fput(fileid,
'\');rc =fwrite(fileid);
275 rc =fput(fileid,
'u');rc =fwrite(fileid);
276 rc =fput(fileid,
'0');rc =fwrite(fileid);
277 rc =fput(fileid,
'0');rc =fwrite(fileid);
278 rc =fput(fileid,
'0');rc =fwrite(fileid);
279 rc =fput(fileid,
'7');rc =fwrite(fileid);
281 else if rec=
'1B'x then
do;
282 rc =fput(fileid,
'\');rc =fwrite(fileid);
283 rc =fput(fileid,
'u');rc =fwrite(fileid);
284 rc =fput(fileid,
'0');rc =fwrite(fileid);
285 rc =fput(fileid,
'0');rc =fwrite(fileid);
286 rc =fput(fileid,
'1');rc =fwrite(fileid);
287 rc =fput(fileid,
'B');rc =fwrite(fileid);
290 rc =fput(fileid,rec);
301 file &fname3 mod TERMSTR=
' ';
307%let fname4=%mf_getuniquefileref();
308proc http method=
'POST'
312 url=
"&base_uri/jobDefinitions/definitions?parentFolderUri=&parentFolderUri";
313 headers
'Content-Type'=
'application/vnd.sas.job.definition+json'
314 %
if &grant_type=authorization_code %then %
do;
315 "Authorization"=
"Bearer &&&access_token_var"
317 "Accept"=
"application/vnd.sas.job.definition+json";
318%
if &debug=1 %then %
do;
323%mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 201)
325 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
328filename &fname1 clear;
329filename &fname2 clear;
330filename &fname3 clear;
331filename &fname4 clear;
332libname &libref1 clear;
337 if symexist(
'_baseurl') then do;
338 url=symget('_baseurl');
339 if subpad(url,length(url)-9,9)='SASStudio'
340 then url=substr(url,1,length(url)-11);
341 else url="&systcpiphostname";
343 else url="&systcpiphostname";
344 call symputx('url',url);
348%put &sysmacroname: Job &name successfully created in &path;
350%put &sysmacroname: Check it out here:;
351%put &sysmacroname:;%put;
352%put &url/SASJobExecution?_PROGRAM=&path/&name;%put;