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

fix: mp_stackdiffs.sas - case when base records are missing, plus tests

This commit is contained in:
munja
2022-01-21 12:19:34 +01:00
parent 9cf2cc3c96
commit 67df4dffeb
2 changed files with 71 additions and 15 deletions

View File

@@ -413,7 +413,7 @@ run;
*/ */
%let missvars=%mf_wordsinstr1butnotstr2( %let missvars=%mf_wordsinstr1butnotstr2(
Str1=%mf_getvarlist(&outadd), Str1=%mf_getvarlist(&outadd),
Str2=%mf_getvarlist(&outbase) Str2=%mf_getvarlist(&baselibds)
); );
%if %length(&missvars)>0 %then %do; %if %length(&missvars)>0 %then %do;
/* add them to the err table */ /* add them to the err table */
@@ -470,7 +470,7 @@ select distinct tgtvar_nm into: missvars separated by ' '
where move_type='M' and is_diff=1; where move_type='M' and is_diff=1;
%let missvars=%mf_wordsinstr1butnotstr2( %let missvars=%mf_wordsinstr1butnotstr2(
Str1=&missvars, Str1=&missvars,
Str2=%mf_getvarlist(&outbase) Str2=%mf_getvarlist(&baselibds)
); );
%if %length(&missvars)>0 %then %do; %if %length(&missvars)>0 %then %do;
/* add them to the err table */ /* add them to the err table */
@@ -488,7 +488,32 @@ select distinct tgtvar_nm into: missvars separated by ' '
delete * from &outmod; delete * from &outmod;
%end; %end;
%else %do; %else %do;
/* now check for records that do not exist (therefore cannot be modified) */
proc sql;
create table &modrec as
select a.*
from &outmod a
left join &base b
on &keyjoin
where a.%scan(&key,1) is null
order by &commakey;
data &moderr;
if 0 then set &errds;
set &modrec;
PK_VARS="&key";
PK_VALS=catx('/',&commakey);
ERR_MSG="Rows cannot be modified as they do not exist on the Base dataset";
keep PK_VARS PK_VALS ERR_MSG;
run;
proc append base=&errds data=&moderr;
run;
/* delete the above records from the outmod table */
data &outmod;
merge &outmod (in=a) &modrec (in=b);
by &key;
if not b;
run;
/* now - we can prepare the final MOD table (which is currently PK only) */
%end; %end;
%if &mdebug=0 %then %do; %if &mdebug=0 %then %do;

View File

@@ -54,7 +54,7 @@ run;
,outdel=work.del1 ,outdel=work.del1
) )
%mp_assertdsobs(work.errds1, %mp_assertdsobs(work.errds1,
desc=Delete1 - no errors, desc=Delete1 - no errs,
test=EQUALS 0 test=EQUALS 0
) )
%mp_assertdsobs(work.del1, %mp_assertdsobs(work.del1,
@@ -78,7 +78,7 @@ run;
,outdel=work.del2 ,outdel=work.del2
) )
%mp_assertdsobs(work.errds2, %mp_assertdsobs(work.errds2,
desc=Delete1 - has errors, desc=Delete1 - has errs,
test=EQUALS 10 test=EQUALS 10
) )
%mp_assertdsobs(work.del1, %mp_assertdsobs(work.del1,
@@ -103,7 +103,7 @@ run;
,outdel=work.del3 ,outdel=work.del3
) )
%mp_assertdsobs(work.errds3, %mp_assertdsobs(work.errds3,
desc=Add3 - no errors, desc=Add3 - no errs,
test=EQUALS 0 test=EQUALS 0
) )
%mp_assertdsobs(work.add3, %mp_assertdsobs(work.add3,
@@ -128,7 +128,7 @@ run;
,outdel=work.del4 ,outdel=work.del4
) )
%mp_assertdsobs(work.errds4, %mp_assertdsobs(work.errds4,
desc=Add4 - 5 errors, desc=Add4 - 5 errs,
test=EQUALS 5 test=EQUALS 5
) )
%mp_assertdsobs(work.add4, %mp_assertdsobs(work.add4,
@@ -153,7 +153,7 @@ run;
,outdel=work.del5 ,outdel=work.del5
) )
%mp_assertdsobs(work.errds5, %mp_assertdsobs(work.errds5,
desc=Add5 - 10 errors, desc=Add5 - 10 errs,
test=EQUALS 10 test=EQUALS 10
) )
%mp_assertdsobs(work.add5, %mp_assertdsobs(work.add5,
@@ -178,7 +178,7 @@ run;
,outdel=work.del6 ,outdel=work.del6
) )
%mp_assertdsobs(work.errds6, %mp_assertdsobs(work.errds6,
desc=Add6 - 0 errors, desc=Add6 - 0 errs,
test=EQUALS 0 test=EQUALS 0
) )
%mp_assertdsobs(work.add6, %mp_assertdsobs(work.add6,
@@ -189,12 +189,12 @@ run;
/** /**
* Modifications test - where base table has missing vars * Modifications test - where base table has missing vars
*/ */
data work.final7; data work.orig7;
set work.final; set work.orig;
drop Coal; drop Coal;
run; run;
%mp_stackdiffs(work.orig %mp_stackdiffs(work.orig7
,work.final7 ,work.final
,CUSTOMER YEAR ,CUSTOMER YEAR
,mdebug=1 ,mdebug=1
,errds=work.errds7 ,errds=work.errds7
@@ -203,7 +203,7 @@ run;
,outdel=work.del7 ,outdel=work.del7
) )
%mp_assertdsobs(work.errds7, %mp_assertdsobs(work.errds7,
desc=Mod7 - 10 errors, desc=Mod7 - 10 errs,
test=EQUALS 10 test=EQUALS 10
) )
%mp_assertdsobs(work.Mod7, %mp_assertdsobs(work.Mod7,
@@ -218,6 +218,37 @@ run;
desc=del7 - 0 records populated , desc=del7 - 0 records populated ,
test=EQUALS 0 test=EQUALS 0
) )
/**
* Modifications test - where base table has missing rows
*/
data work.orig8;
set work.orig;
if _n_ le 16;
run;
%mp_stackdiffs(work.orig8
,work.final7
,CUSTOMER YEAR
,mdebug=1
,errds=work.errds8
,outmod=work.mod8
,outadd=work.add8
,outdel=work.del8
)
%mp_assertdsobs(work.errds8,
desc=Mod4 - 4 errs,
test=EQUALS 4
)
%mp_assertdsobs(work.Mod8,
desc=Mod8 - 6 records populated (missing rows relevant),
test=EQUALS 6
)
%mp_assertdsobs(work.add8,
desc=add8 - 0 records populated ,
test=EQUALS 0
)
%mp_assertdsobs(work.del8,
desc=del8 - 0 records populated ,
test=EQUALS 0
)
%mp_assertscope(COMPARE,Desc=MacVar Scope Check) %mp_assertscope(COMPARE,Desc=MacVar Scope Check)