67%macro mx_execute(program,
77 viyaresult=WEBOUT_JSON,
78 viyacontext=SAS Job Execution compute context
80%local dbg pcnt fref1 fref2 webref webrefpath i webcount var platform jobds respref clearmeref
82%
if &mdebug=1 %then %
do;
83 %put &sysmacroname entry vars:;
90%
if &inputparams ne 0 %then %
do;
93 if not nvalid(name,
'v7') then putlog (_all_)(=);
95 'program
','inputfiles
','inputparams
','debug
','outlib
','outref'
96 ) then putlog (_all_)(=);
99 call symputx(name,quote(cats(value)),
'l');
100 call symputx(cats('pval',x),name,
'l');
101 call symputx('pcnt',x,
'l');
104 %mp_abort(iftrue= (%mf_nobs(&inputparams) ne &pcnt)
106 ,msg=%str(Invalid values in &inputparams)
111%if
"&inputdatasets" ne
"0" %then %do;
112 %if %quote(&inputfiles)=0 %then %let inputfiles=;
113 %do i=1 %to %sysfunc(countw(&inputdatasets,%str( )));
114 %let var=%scan(&inputdatasets,&i,%str( ));
116 %let dsref&i=%mf_getuniquefileref();
117 %mp_ds2csv(&var,outref=&&dsref&i,headerformat=SASJS)
118 %let inputfiles=&inputfiles &&dsref&i:%scan(&var,-1,.);
122%let platform=%mf_getplatform();
123%let fref1=%mf_getuniquefileref();
124%let fref2=%mf_getuniquefileref();
125%let webref=%mf_getuniquefileref();
126%let webrefpath=%sysfunc(pathname(work))/%mf_getuniquename();
128filename &webref
"&webrefpath";
130%if &platform=SASMETA %then %do;
133 %if %quote(&inputfiles) ne 0 %then %do;
134 %let webcount=%sysfunc(countw(&inputfiles));
136 %do i=1 %to &webcount;
137 %let var=%scan(&inputfiles,&i,%str( ));
138 %local webfref&i webname&i;
139 %let webref&i=%scan(&var,1,%str(:));
140 %let webname&i=%scan(&var,2,%str(:));
141 %put webref&i=&&webref&i;
142 %put webname&i=&&webname&i;
145 %else %let webcount=0;
147 proc stp program=
"&program";
148 inputparam _program=
"&program"
149 %do i=1 %to &webcount;
150 %if &webcount=1 %then %do;
151 _webin_fileref=
"&&webref&i"
152 _webin_name=
"&&webname&i"
155 _webin_fileref&i=
"&&webref&i"
156 _webin_name&i=
"&&webname&i"
159 _webin_file_count=
"&webcount"
163 &&pval&i=&&&&&&pval&i
166 %do i=1 %to &webcount;
167 inputfile &&webref&i;
169 outputfile _webout=&webref;
177 if index(_infile_,'>>weboutBEGIN<<') then do;
178 line=tranwrd(_infile_,'>>weboutBEGIN<<
','');
181 else if index(_infile_,'>>weboutEND<<') then do;
182 line=tranwrd(_infile_,'>>weboutEND<<
','');
193 %if &outlib ne 0 %then %do;
194 libname &outlib json (&fref1);
196 %if &outref ne 0 %then %do;
197 filename &outref temp;
198 %mp_binarycopy(inref=&webref,outref=&outref)
201 %if
"&outlogds" ne
"_null_" %then %do;
211 %if
"&outstatus" ne
"0" %then %do;
213 length state $20 uri $256 errmsg $256 platform $10;
216 errmsg='proc stp returns no job status';
223%else %if &platform=SASVIYA %then %do;
227 %let ds1=%mf_getuniquename();
228 %if
"&inputparams" ne
"0" %then %do;
229 proc transpose data=&inputparams out=&ds1;
239 %local webcount i var sasjs_tables;
240 %if %quote(&inputfiles) ne 0 %then %do;
241 %let webcount=%sysfunc(countw(&inputfiles));
243 %do i=1 %to &webcount;
244 %let var=%scan(&inputfiles,&i,%str( ));
245 %local webfref&i webname&i sasjs&i.data;
246 %let webref&i=%scan(&var,1,%str(:));
247 %let webname&i=%scan(&var,2,%str(:));
248 %put webref&i=&&webref&i;
249 %put webname&i=&&webname&i;
251 %let sasjs_tables=&sasjs_tables &&webname&i;
253 infile &&webref&i lrecl=32767;
255 if _n_=1 then call symputx(
"sasjs&i.data",_infile_);
257 "sasjs&i.data",cats(symget(
"sasjs&i.data"),'0D0A'x,_infile_)
259 putlog
"&sysmacroname infile: " _infile_;
263 length sasjs&i.data $32767 sasjs_tables $1000;
264 sasjs&i.data=symget(
"sasjs&i.data");
265 sasjs_tables=symget(
"sasjs_tables");
269 %else %let webcount=0;
272 retain _program
"&program";
273 retain _contextname
"&viyacontext";
275 putlog
"&sysmacroname inputparams:";
280 %let jobds=%mf_getuniquename(prefix=mx_execute_);
281 %mv_jobflow(inds=&ds1
294 %if
"&outlogds" ne
"_null_" %then %do;
296 infile &fref1 lrecl=32767 end=eof;
308 call symputx('uri',uri);
309 putlog
"&sysmacroname: fetching results for " uri;
312 %if
"&outstatus" ne
"0" %then %do;
314 length state $20 uri $256 errmsg $32767 platform $10;
317 set &jobds(keep=state uri);
321 proc datasets lib=work nolist nowarn;
327 %if
"&outstatus" ne
"0" and
"&outref"=
"0" %then %do;
328 %let msgref=%mf_getuniquefileref();
332 %mv_getjobresult(uri=&uri,
340 %if
"&outstatus" ne
"0" %then %do;
343 length line $32767 msg $32767;
345 set &outstatus(keep=state);
346 if state ne 'completed' then do;
347 infile &msgref end=eof lrecl=32767;
350 if found=0 and index(_infile_,'
"MSG"')>0 then do;
351 line=tranwrd(_infile_,
'\"',
'"');
352 if prxmatch('/
"MSG" *: *
"(.*)"/',line) then do;
353 msg=prxchange('s/.*
"MSG" *: *
"(.*)".*/$1/',-1,line);
359 if found then call symputx('abortmsg',msg,
'l');
361 %if %superq(abortmsg) ne %then %do;
364 errmsg=symget('abortmsg');
370 %if %length(&clearmeref)>0 %then %do;
371 filename &msgref clear;
375%else %if &platform=SASJS %then %do;
379 %let respref=&outref;
380 %if
"&respref"=
"0" and
"&outstatus" ne
"0" %then %do;
381 %let respref=%mf_getuniquefileref();
384 %ms_testservice(&program
385 ,inputfiles=&inputfiles
386 ,inputdatasets=&inputdatasets
387 ,inputparams=&inputparams
394 %if
"&outstatus" ne
"0" %then %do;
396 length state $20 uri $256 errmsg $32767 platform $10;
398 retain state 'completed' uri '' errmsg '' platform 'SASJS' abortseen 0;
399 infile &respref end=eof lrecl=32767;
405 if index(_infile_,'
"sasjsAbort"')>0 then do;
409 if abortseen=1 and errmsg='' and index(_infile_,'
"MSG"')>0 then do;
416 line=tranwrd(_infile_,
'\"',
'"');
417 if prxmatch('/
"MSG" *: *
"(.*)"/',line) then
418 errmsg=prxchange('s/.*
"MSG" *: *
"(.*)".*/$1/',-1,line);
425 %if %length(&clearmeref)>0 %then %do;
426 filename &respref clear;
431 %put %str(ERR)OR: Unrecognised platform: &platform;
434%if &mdebug=0 %then %do;
435 filename &fref1 clear;
436 %if &platform ne SASJS %then %do;
437 filename &fref2 clear;
438 filename &webref clear;
442 %put &sysmacroname exit vars:;