1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-03 23:50:06 +00:00

fix: adding test and data logic for re-applying modified records where base table has missing vars

This commit is contained in:
munja
2022-01-21 11:51:47 +01:00
parent dd94215c3b
commit 9cf2cc3c96
2 changed files with 65 additions and 2 deletions

View File

@@ -191,6 +191,7 @@
@li mf_getuniquename.sas
@li mf_islibds.sas
@li mf_nobs.sas
@li mf_wordsinstr1butnotstr2.sas
@li mp_abort.sas
@@ -418,7 +419,7 @@ run;
/* add them to the err table */
data &adderr;
if 0 then set &errds;
set &addrec;
set &outadd;
PK_VARS="&key";
PK_VALS=catx('/',&commakey);
ERR_MSG="Rows cannot be added due to missing base vars: &missvars";
@@ -459,7 +460,36 @@ run;
run;
%end;
/**
* mod check
* Problems - where record does not exist or baseds has modified cols missing
*/
proc sql noprint;
select distinct tgtvar_nm into: missvars separated by ' '
from &auditlibds
where move_type='M' and is_diff=1;
%let missvars=%mf_wordsinstr1butnotstr2(
Str1=&missvars,
Str2=%mf_getvarlist(&outbase)
);
%if %length(&missvars)>0 %then %do;
/* add them to the err table */
data &moderr;
if 0 then set &errds;
set &outmod;
PK_VARS="&key";
PK_VALS=catx('/',&commakey);
ERR_MSG="Rows cannot be modified due to missing base vars: &missvars";
keep PK_VARS PK_VALS ERR_MSG;
run;
proc append base=&errds data=&moderr;
run;
proc sql;
delete * from &outmod;
%end;
%else %do;
%end;
%if &mdebug=0 %then %do;
proc datasets lib=work;

View File

@@ -21,7 +21,7 @@ data work.orig work.deleted work.changed work.appended;
end;
else if _n_ le 20 then do;
output work.orig;
age=99;
coal=ranuni(1)*-1;
output work.changed;
end;
else if _n_ le 30 then do;
@@ -186,5 +186,38 @@ run;
test=EQUALS 10
)
/**
* Modifications test - where base table has missing vars
*/
data work.final7;
set work.final;
drop Coal;
run;
%mp_stackdiffs(work.orig
,work.final7
,CUSTOMER YEAR
,mdebug=1
,errds=work.errds7
,outmod=work.mod7
,outadd=work.add7
,outdel=work.del7
)
%mp_assertdsobs(work.errds7,
desc=Mod7 - 10 errors,
test=EQUALS 10
)
%mp_assertdsobs(work.Mod7,
desc=Mod7 - 0 records populated (structure change relevant),
test=EQUALS 0
)
%mp_assertdsobs(work.add7,
desc=add7 - 0 records populated ,
test=EQUALS 0
)
%mp_assertdsobs(work.del7,
desc=del7 - 0 records populated ,
test=EQUALS 0
)
%mp_assertscope(COMPARE,Desc=MacVar Scope Check)