Loading...
Searching...
No Matches
mpe_getlabels.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mpe_getlabels macro
4 @details Verifies that the output dataset combines:
5 @li NAME from `source`
6 @li LABEL / MEMLABEL from `tgt_ds`
7 @li DD_SHORTDESC / DD_LONGDESC from MPE_DATADICTIONARY where DD_SOURCE
8 contains the `LIB.DSN` reference and DD_TYPE='COLUMN'.
9
10 Scenarios covered:
11
12 1. `source` is a two-part `LIB.DSN` - labels and DD entries are
13 joined directly.
14 2. `source` is a WORK subset without `tgt_ds` - DD entries do not
15 match.
16 3. `source` is a WORK subset with `tgt_ds` set to the underlying
17 `LIB.DSN` - labels come from the target and DD entries match.
18 4. `source` is a WORK subset that contains only a *subset* of the
19 target columns - the output contains only those columns while
20 labels still come from the target.
21
22 <h4> SAS Macros </h4>
23 @li mf_getuniquename.sas
24 @li mf_nobs.sas
25 @li mp_assert.sas
26 @li mp_assertdsobs.sas
27 @li mp_assertscope.sas
28 @li mpe_getlabels.sas
29
30 @author 4GL Apps Ltd
31 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
32 and may not be re-distributed or re-sold without the express permission of
33 4GL Apps Ltd.
34
35**/
36
37/* teardown - remove any seeded rows */
38proc sql;
39delete from &mpelib..mpe_datadictionary
40 where dd_source in (
41 "&mpelib..MPE_X_TEST.PRIMARY_KEY_FIELD",
42 "&mpelib..MPE_X_TEST.SOME_CHAR"
43 );
44quit;
45/* seed MPE_DATADICTIONARY with column-level entries keyed on
46 LIB.DSNAME.COLUMN. &mpelib..MPE_X_TEST is created by testsetup.sas. */
47proc sql;
48insert into &mpelib..mpe_datadictionary set
49 tx_from=0
50 ,tx_to='31DEC5999:23:59:59'dt
51 ,dd_type='COLUMN'
52 ,dd_source="&mpelib..MPE_X_TEST.PRIMARY_KEY_FIELD"
53 ,dd_shortdesc='SHORT PK DESCRIPTION'
54 ,dd_longdesc='LONG PK DESCRIPTION'
55 ,dd_owner=''
56 ,dd_responsible=''
57 ,dd_sensitivity='';
58insert into &mpelib..mpe_datadictionary set
59 tx_from=0
60 ,tx_to='31DEC5999:23:59:59'dt
61 ,dd_type='COLUMN'
62 ,dd_source="&mpelib..MPE_X_TEST.SOME_CHAR"
63 ,dd_shortdesc='SHORT CHAR DESCRIPTION'
64 ,dd_longdesc='LONG CHAR DESCRIPTION'
65 ,dd_owner=''
66 ,dd_responsible=''
67 ,dd_sensitivity='';
68quit;
69
70/* Test 1 - two-part libref.dataset as source */
71%mp_assertscope(SNAPSHOT)
72%mpe_getlabels(COLUMNS,&mpelib..MPE_X_TEST,outds=work.test1)
73%mp_assertscope(COMPARE,
74 desc=Checking macro variables against previous snapshot
75)
76
77data _null_;
78 set work.test1;
79 putlog (_all_)(=);
80run;
81
82%mp_assertdsobs(work.test1,
83 desc=Test 1 - output dataset contains rows (one per column),
84 test=ATLEAST 1,
85 outds=work.test_results
86)
87
88%let shortdesc_hit=0;
89%let longdesc_hit=0;
90data _null_;
91 set work.test1;
92 where upcase(name)='PRIMARY_KEY_FIELD';
93 if desc='SHORT PK DESCRIPTION' then call symputx('shortdesc_hit',1);
94 if longdesc='LONG PK DESCRIPTION' then call symputx('longdesc_hit',1);
95run;
96
97%mp_assert(
98 iftrue=(&shortdesc_hit=1),
99 desc=Test 1 - DD_SHORTDESC returned as desc,
100 outds=work.test_results
101)
102%mp_assert(
103 iftrue=(&longdesc_hit=1),
104 desc=Test 1 - DD_LONGDESC returned as longdesc,
105 outds=work.test_results
106)
107
108/* Test 2 - WORK subset as source, no tgt_ds. DD_SOURCE values do not
109 contain `WORK.SASDATA1`, so DD entries are not applied and desc
110 falls back to whatever LABEL exists on the WORK dataset. */
111data work.sasdata1;
112 set &mpelib..mpe_x_test;
113run;
114
115%mpe_getlabels(COLUMNS,work.sasdata1,outds=work.test2)
116
117data _null_;
118 set work.test2;
119 putlog (_all_)(=);
120run;
121
122%let shortdesc_hit2=0;
123data _null_;
124 set work.test2;
125 where upcase(name)='PRIMARY_KEY_FIELD';
126 if desc='SHORT PK DESCRIPTION' then call symputx('shortdesc_hit2',1);
127run;
128
129%mp_assert(
130 iftrue=(&shortdesc_hit2=0),
131 desc=Test 2 - Without tgt_ds a WORK source does not pick up DD_SHORTDESC,
132 outds=work.test_results
133)
134
135/* Test 3 - WORK subset as source with tgt_ds pointing at the
136 underlying LIB.DSN. Column names are taken from the WORK subset,
137 labels come from the target, DD entries are applied. */
138%mpe_getlabels(COLUMNS,work.sasdata1,tgt_ds=&mpelib..MPE_X_TEST,outds=work.test3)
139
140data _null_;
141 set work.test3;
142 putlog (_all_)(=);
143run;
144
145%mp_assertdsobs(work.test3,
146 desc=Test 3 - output dataset contains rows,
147 test=ATLEAST 1,
148 outds=work.test_results
149)
150
151%let shortdesc_hit3=0;
152%let longdesc_hit3=0;
153data _null_;
154 set work.test3;
155 where upcase(name)='PRIMARY_KEY_FIELD';
156 if desc='SHORT PK DESCRIPTION' then call symputx('shortdesc_hit3',1);
157 if longdesc='LONG PK DESCRIPTION' then call symputx('longdesc_hit3',1);
158run;
159
160%mp_assert(
161 iftrue=(&shortdesc_hit3=1),
162 desc=Test 3 - DD_SHORTDESC returned as desc when tgt_ds is supplied,
163 outds=work.test_results
164)
165%mp_assert(
166 iftrue=(&longdesc_hit3=1),
167 desc=Test 3 - DD_LONGDESC returned as longdesc when tgt_ds is supplied,
168 outds=work.test_results
169)
170
171/* Test 4 - WORK source with a strict subset of the target columns.
172 The output should contain only the columns present in `source`,
173 but labels still come from `tgt_ds`. */
174data work.sasdata2;
175 set &mpelib..mpe_x_test (keep=primary_key_field);
176run;
177
178%mpe_getlabels(COLUMNS,work.sasdata2,tgt_ds=&mpelib..MPE_X_TEST,outds=work.test4)
179
180data _null_;
181 set work.test4;
182 putlog (_all_)(=);
183run;
184
185%mp_assertdsobs(work.test4,
186 desc=Test 4 - output contains exactly one row (matching the source subset),
187 test=EQUALS 1,
188 outds=work.test_results
189)
190
191%let shortdesc_hit4=0;
192data _null_;
193 set work.test4;
194 where upcase(name)='PRIMARY_KEY_FIELD';
195 if desc='SHORT PK DESCRIPTION' then call symputx('shortdesc_hit4',1);
196run;
197
198%mp_assert(
199 iftrue=(&shortdesc_hit4=1),
200 desc=Test 4 - DD_SHORTDESC returned for the retained column,
201 outds=work.test_results
202)
203
204