This program executes a series of unit tests to verify the robustness of the mp_storediffs macro. It generates test data derived from sashelp.class, applies controlled modifications, and uses assertion macros (mp_assert, mp_assertdsobs, mp_assertcolvals) to validate that the reported differences are accurate. Scenarios include mixed changes, no changes, and deletions only.
Data Analysis
Type : MIXTE
Data is generated locally (WORK library) from the sashelp.class system table via DATA steps.
1 Code Block
DATA STEP Data
Explanation : Creation of test tables for the first scenario: an original table, and tables simulating deletions, modifications, and additions.
Copied!
data work.orig work.deleted work.changed work.appended;
set sashelp.class;
if _n_=1 then do;
output work.orig work.deleted;
end;
else if _n_=2 then do;
output work.orig;
age=99;
output work.changed;
end;
else do;
name='Newbie';
output work.appended;
stop;
end;
run;
1
DATA work.orig work.deleted work.changed work.appended;
2
SET sashelp.class;
3
IF _n_=1THENDO;
4
OUTPUT work.orig work.deleted;
5
END;
6
ELSEIF _n_=2THENDO;
7
OUTPUT work.orig;
8
age=99;
9
OUTPUT work.changed;
10
END;
11
ELSEDO;
12
name='Newbie';
13
OUTPUT work.appended;
14
stop;
15
END;
16
RUN;
2 Code Block
MACRO CALL
Explanation : Call to the mp_storediffs macro to compare sashelp.class with work.orig and generate the differences in work.final.
Explanation : Creation of a reference table to validate that the 'tgtvar_type' column of the final table contains only the expected values via mp_assertcolvals.
Copied!
data work.check;
length val $10;
do val='C','N';
output;
end;
run;
%mp_assertcolvals(work.final.tgtvar_type,
checkvals=work.check.val,
desc=All values have a match,
test=ALLVALS
)
1
DATA work.check;
2
LENGTH val $10;
3
DO val='C','N';
4
OUTPUT;
5
END;
6
RUN;
7
%mp_assertcolvals(work.final.tgtvar_type,
8
checkvals=work.check.val,
9
desc=All values have a match,
10
test=ALLVALS
11
)
5 Code Block
DATA STEP Data
Explanation : Test scenario 'No changes': verifies that comparing identical tables produces an empty differences table (0 observations).
Copied!
/* Test for when there are no actual changes */
data work.orig work.deleted work.changed work.appended;
set sashelp.class;
output work.orig;
run;
%mp_storediffs(sashelp.class,work.orig,NAME
,delds=work.deleted
,modds=work.changed
,appds=work.appended
,outds=work.final2
,mdebug=1
)
%mp_assertdsobs(work.final2,
desc=No changes produces 0 records,
test=EQUALS 0,
outds=work.test_results
)
1
/* Test for when there are no actual changes */
2
DATA work.orig work.deleted work.changed work.appended;
3
SET sashelp.class;
4
OUTPUT work.orig;
5
RUN;
6
%mp_storediffs(sashelp.class,work.orig,NAME
7
,delds=work.deleted
8
,modds=work.changed
9
,appds=work.appended
10
,outds=work.final2
11
,mdebug=1
12
)
13
%mp_assertdsobs(work.final2,
14
desc=No changes produces 0 records,
15
test=EQUALS 0,
16
outds=work.test_results
17
)
6 Code Block
DATA STEP Data
Explanation : Test scenario 'Deletions only': simulates the deletion of rows and verifies that the number of detected differences matches expectations (70 records).
Copied!
/* Test for deletes only */
data work.orig work.deleted work.changed work.appended;
set sashelp.class;
output work.orig;
if _n_>5 then output work.deleted;
run;
%mp_storediffs(sashelp.class,work.orig,NAME
,delds=work.deleted
,modds=work.changed
,appds=work.appended
,outds=work.final3
,mdebug=1
)
%mp_assertdsobs(work.final3,
desc=Delete has 70 records,
test=EQUALS 70,
outds=work.test_results
)
1
/* Test for deletes only */
2
DATA work.orig work.deleted work.changed work.appended;
3
SET sashelp.class;
4
OUTPUT work.orig;
5
IF _n_>5THENOUTPUT work.deleted;
6
RUN;
7
8
%mp_storediffs(sashelp.class,work.orig,NAME
9
,delds=work.deleted
10
,modds=work.changed
11
,appds=work.appended
12
,outds=work.final3
13
,mdebug=1
14
)
15
%mp_assertdsobs(work.final3,
16
desc=Delete has 70 records,
17
test=EQUALS 70,
18
outds=work.test_results
19
)
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.