Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
ml_gsubfile.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing ml_gsubfile macro
4
5 <h4> SAS Macros </h4>
6 @li ml_gsubfile.sas
7 @li mf_mkdir.sas
8 @li mp_assert.sas
9
10 @details The macro substitutes the value of the macro variable named by
11 patternvar with the value of the one named by replacevar, in place.
12
13**/
14
15%let root=%sysfunc(pathname(work))/gsub;
16%mf_mkdir(&root)
17%let target=&root/seed.txt;
18%let pattern=WORLD;
19%let repl=there;
20
21data _null_;
22 file "&target";
23 put 'hello WORLD';
24run;
25
26%let file=&target;
27%let outfile=0;
28%let patternvar=pattern;
29%let replacevar=repl;
30
31%ml_gsubfile()
32
33%let subbed=0;
34%let stale=0;
35
36data _null_;
37 infile "&target" truncover;
38 input;
39 if index(_infile_,'there')>0 then call symputx('subbed',1,'g');
40 if index(_infile_,'WORLD')>0 then call symputx('stale',1,'g');
41run;
42
43%mp_assert(
44 iftrue=(&subbed=1),
45 desc=Checking that the pattern is replaced in the file,
46 outds=work.test_results
47)
48
49%mp_assert(
50 iftrue=(&stale=0),
51 desc=Checking that no copy of the original pattern is left,
52 outds=work.test_results
53)