Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_setkeyvalue.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_setkeyvalue macro
4
5 <h4> SAS Macros </h4>
6 @li mp_setkeyvalue.sas
7 @li mf_getkeyvalue.sas
8 @li mp_assert.sas
9
10**/
11
12%mp_setkeyvalue(numkey,42,type=N)
13%mp_setkeyvalue(charkey,a value)
14%mp_setkeyvalue(charkey,another value)
15
16proc sql noprint;
17 select count(*) into: n_rows from work.mp_setkeyvalue;
18 select count(*) into: n_num from work.mp_setkeyvalue where key='numkey';
19quit;
20
21%mp_assert(
22 iftrue=(&n_rows=2),
23 desc=Checking that setting the same key twice leaves a single row,
24 outds=work.test_results
25)
26
27%mp_assert(
28 iftrue=(%mf_getkeyvalue(numkey)=42),
29 desc=Checking that a numeric value round trips,
30 outds=work.test_results
31)
32
33/* the value carries a space, so it is compared in a data step rather than
34 through %EVAL */
35%let charval=%sysfunc(strip(%mf_getkeyvalue(charkey)));
36
37data work.kv_check;
38 length charval $40;
39 charval="%superq(charval)";
40 ok=0;
41 if charval='another value' then ok=1;
42run;
43
44proc sql noprint;
45 select ok into: kv_ok from work.kv_check;
46quit;
47
48%mp_assert(
49 iftrue=(&kv_ok=1),
50 desc=Checking that the second value for a key replaces the first,
51 outds=work.test_results
52)