Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_stripdiffs.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_stripdiffs.sas macro
4 @details
5
6 <h4> SAS Macros </h4>
7 @li mp_assert.sas
8 @li mp_assertscope.sas
9 @li mp_ds2md.sas
10 @li mp_stripdiffs.sas
11
12**/
13
14/* make an adjustable base dataset */
15/* use a composite key also (name weight) */
16libname libby (work);
17data libby.class;
18 set sashelp.class;
19run;
20
21/* first, store some diffs */
22data work.orig work.deleted work.changed work.appended;
23 set libby.class;
24 if _n_=1 then do;
25 call symputx('delname',name);
26 output work.orig work.deleted;
27 end;
28 else if _n_=2 then do;
29 output work.orig;
30 call symputx('modname',name);
31 call symputx('modval',age);
32 age=99;
33 output work.changed;
34 end;
35 else do;
36 name='Newbie';
37 output work.appended;
38 stop;
39 end;
40run;
41%mp_storediffs(libby.class,work.orig,NAME WEIGHT
42 ,delds=work.deleted
43 ,modds=work.changed
44 ,appds=work.appended
45 ,outds=work.audit
46 ,loadref=UPLOAD1
47 ,mdebug=0
48)
49%mp_ds2md(work.audit)
50%mp_assert(
51 iftrue=(&syscc=0),
52 desc=Checking preparation case,
53 outds=work.test_results
54)
55
56/* apply the changes */
57proc sql;
58delete from libby.class where name in ("&delname","&modname");
59proc append base=libby.class data=work.appended;
60proc append base=libby.class data=work.changed;
61run;
62
63/* now, prepare the revert dataset */
64%mp_assertscope(SNAPSHOT)
65%mp_stripdiffs(libby.class
66 ,UPLOAD1
67 ,work.audit
68 ,outds=work.mp_stripdiffs
69 ,mdebug=1
70)
71%mp_ds2md(work.mp_stripdiffs)
72%mp_assertscope(COMPARE)
73
74%mp_assert(
75 iftrue=(&syscc=0),
76 desc=Checking error condition,
77 outds=work.test_results
78)
79
80%let delpass=0;
81%let modpass=0;
82%let addpass=0;
83data _null_;
84 set work.mp_stripdiffs;
85 if upcase(_____DELETE__THIS__RECORD_____)='NO' and name="&delname"
86 then call symputx('delpass',1);
87 if name="&modname" and age=&modval then call symputx('modpass',1);
88 if upcase(_____DELETE__THIS__RECORD_____)='YES' and name="Newbie"
89 then call symputx('addpass',1);
90run;
91
92%mp_assert(
93 iftrue=(&delpass=1),
94 desc=Ensuring deleted record is back in the dataset,
95 outds=work.test_results
96)
97%mp_assert(
98 iftrue=(&modpass=1),
99 desc=Ensuring modified record now has old value,
100 outds=work.test_results
101)
102%mp_assert(
103 iftrue=(&addpass=1),
104 desc=Ensuring added record is now marked for deletion,
105 outds=work.test_results
106)