diff --git a/base/mp_stackdiffs.sas b/base/mp_stackdiffs.sas index e763ae4..a87fd64 100644 --- a/base/mp_stackdiffs.sas +++ b/base/mp_stackdiffs.sas @@ -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; diff --git a/tests/crossplatform/mp_stackdiffs.test.sas b/tests/crossplatform/mp_stackdiffs.test.sas index 753b55c..121e88f 100644 --- a/tests/crossplatform/mp_stackdiffs.test.sas +++ b/tests/crossplatform/mp_stackdiffs.test.sas @@ -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) \ No newline at end of file