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

feat: modification for mp_stackdiffs.sas and associated tests

This commit is contained in:
munja
2022-01-21 13:59:54 +01:00
parent 67df4dffeb
commit b69c3b7a78
2 changed files with 57 additions and 4 deletions

View File

@@ -188,6 +188,7 @@
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mf_existvarlist.sas @li mf_existvarlist.sas
@li mf_getquotedstr.sas @li mf_getquotedstr.sas
@li mf_getuniquefileref.sas
@li mf_getuniquename.sas @li mf_getuniquename.sas
@li mf_islibds.sas @li mf_islibds.sas
@li mf_nobs.sas @li mf_nobs.sas
@@ -200,6 +201,10 @@
@li mp_stackdiffs.test.sas @li mp_stackdiffs.test.sas
@li mp_storediffs.sas @li mp_storediffs.sas
@todo The current approach assumes that a variable called KEY_HASH is not on
the base table. This part will need to be refactored (eg using
mf_getuniquename.sas) when such a use case arises.
@version 9.2 @version 9.2
@author Allan Bowe @author Allan Bowe
**/ **/
@@ -245,10 +250,10 @@
/* set up macro vars */ /* set up macro vars */
%local prefix dslist x var keyjoin commakey keepvars missvars; %local prefix dslist x var keyjoin commakey keepvars missvars fref;
%let prefix=%substr(%mf_getuniquename(),1,25); %let prefix=%substr(%mf_getuniquename(),1,25);
%let dslist=ds1d ds2d ds3d ds1a ds2a ds3a ds1m ds2m ds3m pks dups base %let dslist=ds1d ds2d ds3d ds1a ds2a ds3a ds1m ds2m ds3m pks dups base
delrec delerr addrec adderr; delrec delerr addrec adderr modrec moderr;
%do x=1 %to %sysfunc(countw(&dslist)); %do x=1 %to %sysfunc(countw(&dslist));
%let var=%scan(&dslist,&x); %let var=%scan(&dslist,&x);
%local &var; %local &var;
@@ -296,6 +301,7 @@ run;
data &outdel; data &outdel;
set &ds2d; set &ds2d;
set &ds3d; set &ds3d;
drop key_hash;
run; run;
proc sort; proc sort;
by &key; by &key;
@@ -324,6 +330,10 @@ run;
data &outadd; data &outadd;
set &ds2a; set &ds2a;
set &ds3a; set &ds3a;
drop key_hash;
run;
proc sort;
by &key;
run; run;
/** /**
@@ -514,6 +524,28 @@ select distinct tgtvar_nm into: missvars separated by ' '
if not b; if not b;
run; run;
/* now - we can prepare the final MOD table (which is currently PK only) */ /* now - we can prepare the final MOD table (which is currently PK only) */
proc sql(undo_policy=none);
create table &outmod as
select a.* /* includes KEY_HASH from audit ds */
from &outmod a
inner join &base b
on &keyjoin
order by &commakey;
/* now - to update outmod with modified (is_diff=1) values */
%let fref=%mf_getuniquefileref();
data _null_;
file &fref;
set &auditlibds(where=(move_type='D')) end=lastobs;
by key_hash;
if _n_=1 then put 'proc sql;';
if first.key_hash then put "update &outmod set ";
comma=ifc(first.key_hash=0,',',' ');
if tgtvar_type='C' then put ' ' comma TGTVAR_NM '=trim("' NEWVAL_CHAR '")';
if last.key_hash then put ' where key_hash=trim("' key_hash '");';
if lastobs then put 'alter &outmod drop key_hash';
run;
%inc &fref/source2;
%end; %end;
%if &mdebug=0 %then %do; %if &mdebug=0 %then %do;
@@ -523,4 +555,4 @@ select distinct tgtvar_nm into: missvars separated by ' '
%end; %end;
%mend mp_stackdiffs; %mend mp_stackdiffs;
/** @endcond */ /** @endcond */`

View File

@@ -21,7 +21,8 @@ data work.orig work.deleted work.changed work.appended;
end; end;
else if _n_ le 20 then do; else if _n_ le 20 then do;
output work.orig; output work.orig;
coal=ranuni(1)*-1; coal=-1;
coaltip='modified';
output work.changed; output work.changed;
end; end;
else if _n_ le 30 then do; else if _n_ le 30 then do;
@@ -251,4 +252,24 @@ run;
test=EQUALS 0 test=EQUALS 0
) )
/**
* Modifications test - were diffs actually applied?
*/
data work.checkds;
charchk='modified';
numchk=-1;
output;
run;
%mp_assertcolvals(work.mod8.coal,
checkvals=work.checkds.numchk,
desc=Modified numeric value matches,
test=ALLVALS
)
%mp_assertcolvals(work.mod8.coaltip,
checkvals=work.checkds.charchk,
desc=Modified char value matches,
test=ALLVALS
)
%mp_assertscope(COMPARE,Desc=MacVar Scope Check) %mp_assertscope(COMPARE,Desc=MacVar Scope Check)