Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_replace.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_replace.sas macro
4
5 <h4> SAS Macros </h4>
6 @li mp_replace.sas
7 @li mp_assert.sas
8 @li mp_assertscope.sas
9
10**/
11
12
13%let test1="&sasjswork/file.txt";
14%let str=replace/me;
15%let rep=with/this;
16data _null_;
17 file &test1;
18 put 'blahblah';
19 put "blahblah&str.blah";
20 put 'blahblahblah';
21run;
22%mp_assertscope(SNAPSHOT)
23%mp_replace(&test1, findvar=str, replacevar=rep)
24%mp_assertscope(COMPARE)
25data _null_;
26 infile &test1;
27 input;
28 if _n_=2 then call symputx('test1result',_infile_);
29run;
30
31%mp_assert(
32 iftrue=("&test1result" = "blahblah&rep.blah"),
33 desc=Checking first replace,
34 outds=work.test_results
35)
36
37
38%let test2="&sasjswork/file2.txt";
39%let str=%str(replacewith trailing spaces );
40%let rep=%str( with more spaces );
41data _null_;
42 file &test2 lrecl=500;
43 put 'blahblah';
44 put "blahblah&str.blah&str. replace &str.X";
45 put "blahbreplacewith&str.spacesahblah";
46run;
47%mp_replace(&test2, findvar=str, replacevar=rep)
48
49data _null_;
50 infile &test2 lrecl=500;
51 input;
52 if _n_=2 then call symputx('test2resulta',_infile_);
53 if _n_=3 then call symputx('test2resultb',_infile_);
54run;
55
56%mp_assert(
57 iftrue=("&test2resulta" = "blahblah&rep.blah&rep. replace &rep.X"),
58 desc=Checking second replace 2nd row,
59 outds=work.test_results
60)
61%mp_assert(
62 iftrue=("&test2resultb" = "blahbreplacewith&rep.spacesahblah"),
63 desc=Checking second replace 3rd row,
64 outds=work.test_results
65)
66
67
68%let test3="&sasjswork/file3.txt";
69%let str=%str(replace.string.with.dots );
70%let rep=%str( more.dots);
71data _null_;
72 file &test3 lrecl=500;
73 put 'blahblah';
74 put "blahblah&str.blah&str. replace &str.X";
75 put "blahbreplacewith&str.spacesahblah";
76run;
77%mp_replace(&test3, findvar=str, replacevar=rep)
78
79data _null_;
80 infile &test3 lrecl=500;
81 input;
82 if _n_=2 then call symputx('test3resulta',_infile_);
83 if _n_=3 then call symputx('test3resultb',_infile_);
84run;
85
86%mp_assert(
87 iftrue=("&test3resulta" = "blahblah&rep.blah&rep. replace &rep.X"),
88 desc=Checking third replace 2nd row (dots),
89 outds=work.test_results
90)
91%mp_assert(
92 iftrue=("&test3resultb" = "blahbreplacewith&rep.spacesahblah"),
93 desc=Checking third replace 3rd row (dots),
94 outds=work.test_results
95)