Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mf_getquotedstr.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mf_getquotedstr macro
4
5 <h4> SAS Macros </h4>
6 @li mf_getquotedstr.sas
7 @li mp_assert.sas
8 @li mp_assertscope.sas
9
10 @details The returned strings contain commas, so they are compared in a data
11 step rather than through %EVAL.
12
13**/
14
15%mp_assertscope(SNAPSHOT)
16%put scope check:%mf_getquotedstr(blah blah blah);
17%mp_assertscope(COMPARE,
18 desc=Checking that mf_getquotedstr does not leak scope,
19 outds=work.test_results
20)
21
22%let q_default=%mf_getquotedstr(blah blah blah);
23%let q_double=%mf_getquotedstr(these words are double quoted,quote=D);
24%let q_none=%mf_getquotedstr(these words are double quoted,quote=N);
25%let q_empty=%mf_getquotedstr();
26%let q_dlm=%mf_getquotedstr(a b c,dlm=%str(|));
27
28data work.quoted_check;
29 length case $10 actual expect $200;
30 case='default';
31 actual="%superq(q_default)";
32 expect="'blah','blah','blah'";
33 output;
34 case='double';
35 actual="%superq(q_double)";
36 expect='"these","words","are","double","quoted"';
37 output;
38 case='none';
39 actual="%superq(q_none)";
40 expect="these,words,are,double,quoted";
41 output;
42 case='empty';
43 actual="%superq(q_empty)";
44 expect="''";
45 output;
46 case='dlm';
47 actual="%superq(q_dlm)";
48 expect="'a'|'b'|'c'";
49 output;
50run;
51
52proc sql noprint;
53 select count(*) into: n_checked from work.quoted_check;
54 select count(*) into: n_bad from work.quoted_check where actual ne expect;
55quit;
56
57%mp_assert(
58 iftrue=(&n_checked=5),
59 desc=Checking that all five quoted forms were compared,
60 outds=work.test_results
61)
62
63%mp_assert(
64 iftrue=(&n_bad=0),
65 desc=Checking each quoted form against the string it should return,
66 outds=work.test_results
67)