Macros for SAS Application Developers
https://github.com/sasjs/core
mf_writefile.test.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Testing mf_writefile.sas macro
4 
5  <h4> SAS Macros </h4>
6  @li mf_writefile.sas
7  @li mp_assert.sas
8 
9 **/
10 
11 %mf_writefile(&sasjswork/myfile.txt,l1=some content,l2=more content)
12 data _null_;
13  infile "&sasjswork/myfile.txt";
14  input;
15  if _n_=2 then call symputx('test1',_infile_);
16 run;
17 
18 %mp_assert(
19  iftrue=(&syscc=0),
20  desc=Check code ran without errors,
21  outds=work.test_results
22 )
23 %mp_assert(
24  iftrue=(&test1=more content),
25  desc=Checking line was created,
26  outds=work.test_results
27 )
28 
29 %mf_writefile(&sasjswork/myfile.txt,l1=some content,l2=different content)
30 data _null_;
31  infile "&sasjswork/myfile.txt";
32  input;
33  if _n_=2 then call symputx('test2',_infile_);
34 run;
35 
36 %mp_assert(
37  iftrue=(&syscc=0),
38  desc=Check code ran without errors for test2,
39  outds=work.test_results
40 )
41 %mp_assert(
42  iftrue=(&test2=different content),
43  desc=Checking second line was overwritten,
44  outds=work.test_results
45 )
46 
47 %global test3 test4;
48 %mf_writefile(&sasjswork/myfile.txt
49  ,mode=a
50  ,l1=%str(aah, content)
51  ,l2=append content
52 )
53 data _null_;
54  infile "&sasjswork/myfile.txt";
55  input;
56  if _n_=2 then call symputx('test3',_infile_);
57  if _n_=4 then call symputx('test4',_infile_);
58 run;
59 
60 %mp_assert(
61  iftrue=(&syscc=0),
62  desc=Check code ran without errors for test2,
63  outds=work.test_results
64 )
65 %mp_assert(
66  iftrue=(&test3=different content),
67  desc=Checking second line was not overwritten,
68  outds=work.test_results
69 )
70 %mp_assert(
71  iftrue=(&test4=append content),
72  desc=Checking fourth line was appended,
73  outds=work.test_results
74 )