Submits a sas program in batch using systask
%macro batch_run(tab=,timeout=120,type=tfl,subtype=production,progdir=programs);

%let fpath="&path\&type\&subtype\&progdir\&tab..sas";
%let logfile=&path\&type\&subtype\&progdir\log\&tab..log;
%if %fileexist(tab=rt_nonctc_haem_shift) = 0 %then %do;

data _null_;
length command $
2000;

command= strip(cat (
'systask command   ',"'",'"C:\Program Files\SASHome\x86\SASFoundation\9.3\sas.exe"'  ,     
  
' -sysin ''"',"&path",'\',"&type","\&subtype","\&progdir\","&tab",'.sas"',  
  
' -log ''"'"&path",'\',"&type","\&subtype","\&progdir\log\","&tab",'.log"'
  
' -print ','"'"&path",'\',"&type","\&subtype","\&progdir\lst\","&tab",'.lst"',
  
' -noterminal -rsasuser -nosplash -nologo ',"'", ' status=runstat taskname=&tab;  ')) ;
call symput(
'command',command);
run;
&command;
waitfor &tab timeout=&timeout;

proc sql;
insert into joblog.jobs
set  study=
"&study",
     path=
"&path",
     job=
"&tab",
     status=put(&runstat,
jstat.),
     status_cd=&runstat,
     runtime=put(datetime(),
datetime20.);
quit;
%logscan(logfile=&
logfile.);
%if &runstat = 0 %then %put &tab ran ok;
%else %if &runstat = 2 %then %put job failed with errors check &logfile.;
%else %if &runstat = 1 %then %put job completed with warning check &logfile.;
%else %put job failed  check &logfile.;
%end;
%else %put program does not exist check name;
%mend;