1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-11 06:24:35 +00:00

Merge pull request #25 from sasjs/dcfixes

fix: more logging in mp_abort, fixing job test, better return values …
This commit is contained in:
Allan Bowe
2021-05-11 23:37:25 +03:00
committed by GitHub
5 changed files with 45 additions and 27 deletions

View File

@@ -74,7 +74,7 @@
input; input;
i=1; i=1;
stoploop=0; stoploop=0;
if _n_ ge &logline-5 and stoploop=0 then do until (i>12); if _n_ ge &logline-15 and stoploop=0 then do until (i>22);
call symputx('logmsg',catx('\n',symget('logmsg'),_infile_)); call symputx('logmsg',catx('\n',symget('logmsg'),_infile_));
input; input;
i+1; i+1;

View File

@@ -33,12 +33,13 @@
@returns The &outds table containing any bad rows, plus a REASON_CD column. @returns The &outds table containing any bad rows, plus a REASON_CD column.
@param [in] inds The table to be checked, with the format above @param [in] inds The table to be checked, with the format above
@param [in] targetds= The target dataset against which to verify VARIABLE_NM @param [in] targetds= The target dataset against which to verify VARIABLE_NM.
This must be available (ie, the library must be assigned).
@param [out] abort= (YES) If YES will call mp_abort.sas on any exceptions @param [out] abort= (YES) If YES will call mp_abort.sas on any exceptions
@param [out] outds= The output table, which is a copy of the &inds. table @param [out] outds= The output table, which is a copy of the &inds. table
plus a REASON_CD column, containing only bad records. If bad records found, plus a REASON_CD column, containing only bad records. If bad records found,
the SYSCC value will be set to 1008 (general data problem). Downstream the SYSCC value will be set to 1008 (general data problem). Downstream
processes should check this table (and return code) before continuing. processes should check this table (and return code) before continuing.
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mp_abort.sas @li mp_abort.sas
@@ -84,41 +85,52 @@
* quotes, commas, periods and spaces. * quotes, commas, periods and spaces.
* Only numeric values should remain * Only numeric values should remain
*/ */
%local reason_cd; %local reason_cd nobs;
%let nobs=0;
data &outds; data &outds;
/*length GROUP_LOGIC SUBGROUP_LOGIC $3 SUBGROUP_ID 8 VARIABLE_NM $32 /*length GROUP_LOGIC SUBGROUP_LOGIC $3 SUBGROUP_ID 8 VARIABLE_NM $32
OPERATOR_NM $10 RAW_VALUE $4000;*/ OPERATOR_NM $10 RAW_VALUE $4000;*/
set &inds; set &inds;
length reason_cd $32; length reason_cd $4032;
/* closed list checks */ /* closed list checks */
if GROUP_LOGIC not in ('AND','OR') then do; if GROUP_LOGIC not in ('AND','OR') then do;
REASON_CD='GROUP_LOGIC should be either AND or OR'; REASON_CD='GROUP_LOGIC should be AND/OR, not:'!!cats(GROUP_LOGIC);
putlog REASON_CD= GROUP_LOGIC=; putlog REASON_CD= GROUP_LOGIC=;
call symputx('reason_cd',reason_cd,'l');
call symputx('nobs',_n_,'l');
output; output;
end; end;
if SUBGROUP_LOGIC not in ('AND','OR') then do; if SUBGROUP_LOGIC not in ('AND','OR') then do;
REASON_CD='SUBGROUP_LOGIC should be either AND or OR'; REASON_CD='SUBGROUP_LOGIC should be AND/OR, not:'!!cats(SUBGROUP_LOGIC);
putlog REASON_CD= SUBGROUP_LOGIC=; putlog REASON_CD= SUBGROUP_LOGIC=;
call symputx('reason_cd',reason_cd,'l');
call symputx('nobs',_n_,'l');
output; output;
end; end;
if mod(SUBGROUP_ID,1) ne 0 then do; if mod(SUBGROUP_ID,1) ne 0 then do;
REASON_CD='SUBGROUP_ID should be integer'; REASON_CD='SUBGROUP_ID should be integer, not '!!left(subgroup_id);
putlog REASON_CD= SUBGROUP_ID=; putlog REASON_CD= SUBGROUP_ID=;
call symputx('reason_cd',reason_cd,'l');
call symputx('nobs',_n_,'l');
output; output;
end; end;
if upcase(VARIABLE_NM) not in if upcase(VARIABLE_NM) not in
(%upcase(%mf_getvarlist(&targetds,dlm=%str(,),quote=SINGLE))) (%upcase(%mf_getvarlist(&targetds,dlm=%str(,),quote=SINGLE)))
then do; then do;
REASON_CD="VARIABLE_NM not in &targetds"; REASON_CD="Variable "!!cats(variable_nm)!!" not in &targetds";
putlog REASON_CD= VARIABLE_NM=; putlog REASON_CD= VARIABLE_NM=;
call symputx('reason_cd',reason_cd,'l');
call symputx('nobs',_n_,'l');
output; output;
end; end;
if OPERATOR_NM not in if OPERATOR_NM not in
('=','>','<','<=','>=','BETWEEN','IN','NOT IN','NE','CONTAINS') ('=','>','<','<=','>=','BETWEEN','IN','NOT IN','NE','CONTAINS')
then do; then do;
REASON_CD='Invalid OPERATOR_NM'; REASON_CD='Invalid OPERATOR_NM: '!!left(OPERATOR_NM);
putlog REASON_CD= OPERATOR_NM=; putlog REASON_CD= OPERATOR_NM=;
call symputx('reason_cd',reason_cd,'l');
call symputx('nobs',_n_,'l');
output; output;
end; end;
@@ -128,8 +140,10 @@ data &outds;
if substr(raw_value,1,1) ne '(' if substr(raw_value,1,1) ne '('
or substr(cats(reverse(raw_value)),1,1) ne ')' or substr(cats(reverse(raw_value)),1,1) ne ')'
then do; then do;
REASON_CD='Missing brackets in RAW_VALUE'; REASON_CD='Missing start/end bracket in RAW_VALUE';
putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ; putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
call symputx('reason_cd',reason_cd,'l');
call symputx('nobs',_n_,'l');
output; output;
end; end;
else raw_value1=substr(raw_value,2,max(length(raw_value)-2,0)); else raw_value1=substr(raw_value,2,max(length(raw_value)-2,0));
@@ -150,27 +164,24 @@ data &outds;
/* output records that contain values other than digits and spaces */ /* output records that contain values other than digits and spaces */
if notdigit(compress(raw_value3,' '))>0 then do; if notdigit(compress(raw_value3,' '))>0 then do;
putlog raw_value3= $hex32.; putlog raw_value3= $hex32.;
REASON_CD='Invalid RAW_VALUE'; REASON_CD=cats('Invalid RAW_VALUE:',raw_value);
putlog REASON_CD= raw_value= raw_value1= raw_value2= raw_value3=; putlog REASON_CD= raw_value= raw_value1= raw_value2= raw_value3=;
call symputx('reason_cd',reason_cd,'l');
call symputx('nobs',_n_,'l');
output; output;
end; end;
run; run;
%local nobs;
%let nobs=0;
data _null_; data _null_;
set &outds end=last; set &outds end=last;
putlog (_all_)(=); putlog (_all_)(=);
if last then do;
call symputx('REASON_CD',reason_cd,'l');
call symputx('nobs',_n_,'l');
end;
run; run;
%mp_abort(iftrue=(&abort=YES and &nobs>0), %mp_abort(iftrue=(&abort=YES and &nobs>0),
mac=&sysmacroname, mac=&sysmacroname,
msg=%str(&nobs filter issues in &inds, reason: &reason_cd, details in &outds) msg=%str(Data issue: %superq(reason_cd))
) )
%if &nobs>0 %then %do; %if &nobs>0 %then %do;

View File

@@ -95,7 +95,8 @@ filename &fref1 clear;
run; run;
%mp_abort( %mp_abort(
mac=&sysmacroname, mac=&sysmacroname,
msg=%str(Filter issues in &inref: %quote(&reason_cd)) msg=%str(Filter validation issues. ERR=%superq(SYSERRORTEXT)
, WARN=%superq(SYSWARNINGTEXT) )
) )
%end; %end;
%let syscc=1008; %let syscc=1008;

View File

@@ -61,7 +61,7 @@
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%put output location=&jref; %put output location=&jref;
%if &action=OPEN %then %do; %if &action=OPEN %then %do;
OPTIONS NOBOMFILE; options nobomfile;
data _null_;file &jref encoding='utf-8'; data _null_;file &jref encoding='utf-8';
put '{"START_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '"'; put '{"START_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '"';
run; run;

View File

@@ -19,6 +19,7 @@
filename testref temp; filename testref temp;
data _null_; data _null_;
file testref; file testref;
put 'data;run;';
put 'endsas;'; put 'endsas;';
run; run;
%mv_createjob( %mv_createjob(
@@ -31,7 +32,7 @@ run;
%mv_jobexecute( %mv_jobexecute(
path=&mcTestAppLoc/jobs/temp, path=&mcTestAppLoc/jobs/temp,
name=testjob, name=testjob,
outds=work.info, outds=work.info
) )
%* Wait for it to finish; %* Wait for it to finish;
@@ -52,10 +53,15 @@ run;
data _null_; data _null_;
infile mylog; infile mylog end=eof;
input; input;
if index(_infile_,'endsas;') then call symputx('found',1); putlog _infile_;
else call symputx('found',0); retain found 0;
if index(_infile_,'endsas;') then do;
found=1;
call symputx('found',found);
end;
else if eof and found ne 1 then call symputx('found',0);
run; run;
%mp_assert( %mp_assert(