Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_ds2inserts.test.2.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_ds2inserts.sas macro with special missing values
4
5 <h4> SAS Macros </h4>
6 @li mp_assert.sas
7 @li mp_ds2inserts.sas
8
9**/
10
11/* numeric cells holding special missings, alongside a plain missing and an
12 ordinary value */
13data work.spm(keep=id n c);
14 id=1; n=._; c='a'; output;
15 id=2; n=.A; c='b'; output;
16 id=3; n=.; c='c'; output;
17 id=4; n=42; c='d'; output;
18run;
19
20filename testref temp;
21%mp_ds2inserts(work.spm,outref=testref,schema=work,outds=copy,flavour=SAS)
22
23/* both special missings must reach the statement with their leading period */
24%let periodflg=0;
25data _null_;
26 infile testref end=eof;
27 retain found 0;
28 input;
29 if index(_infile_,'n=._') or index(_infile_,'n=.A') then found+1;
30 if eof then call symputx('periodflg',found,'l');
31run;
32%mp_assert(
33 iftrue=(&periodflg=2),
34 desc=Checking the period is written for special missings,
35 outds=work.test_results
36)
37
38/* empty target with the same structure, loaded from the generated inserts */
39data work.copy;
40 if 0 then set work.spm;
41 stop;
42run;
43proc sql;
44%inc testref;
45quit;
46
47/* the inserts must actually load - an invalid statement leaves the target
48 empty, and the compare below would then run in syntax-check mode */
49%let copyobs=0;
50data _null_;
51 if 0 then set work.copy nobs=nn;
52 call symputx('copyobs',nn,'l');
53 stop;
54run;
55%mp_assert(
56 iftrue=(&copyobs=4),
57 desc=Checking all four rows were inserted,
58 outds=work.test_results
59)
60
61/* the loaded values must match the source, special missings included - a plain
62 ne catches ._ vs . and .A vs .B, as special missings compare as values */
63proc sort data=work.spm out=work.spm_s;
64 by id;
65run;
66proc sort data=work.copy out=work.copy_s;
67 by id;
68run;
69%let valfail=0;
70data _null_;
71 merge work.spm_s(in=a rename=(n=n_exp c=c_exp)) work.copy_s(in=b) end=eof;
72 by id;
73 retain bad 0;
74 if not (a and b) then bad+1;
75 else if n ne n_exp or c ne c_exp then bad+1;
76 if eof then call symputx('valfail',bad,'l');
77run;
78%mp_assert(
79 iftrue=(&valfail=0),
80 desc=Checking inserts round trip special missing values,
81 outds=work.test_results
82)