Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_chop.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_chop.sas macro
4
5 <h4> SAS Macros </h4>
6 @li mp_chop.sas
7 @li mp_assert.sas
8 @li mp_assertscope.sas
9
10**/
11
12/* prep input string */
13%let src="%sysfunc(pathname(work))/file.txt";
14%let str=Chop here!;
15%let out1="%sysfunc(pathname(work))/file1.txt";
16%let out2="%sysfunc(pathname(work))/file2.txt";
17%let out3="%sysfunc(pathname(work))/file3.txt";
18%let out4="%sysfunc(pathname(work))/file4.txt";
19
20data _null_;
21 file &src;
22 put "startsection&str.endsection";
23run;
24
25
26%mp_assertscope(SNAPSHOT)
27%mp_chop(&src, matchvar=str, keep=FIRST, outfile=&out1)
28%mp_chop(&src, matchvar=str, keep=LAST, outfile=&out2)
29%mp_chop(&src, matchvar=str, keep=FIRST, matchpoint=END, outfile=&out3)
30%mp_chop(&src, matchvar=str, keep=LAST, matchpoint=END, outfile=&out4)
31%mp_assertscope(COMPARE)
32
33data _null_;
34 infile &out1 lrecl=200;
35 input;
36 call symputx('test1',_infile_);
37data _null_;
38 infile &out2 lrecl=200;
39 input;
40 call symputx('test2',_infile_);
41data _null_;
42 infile &out3 lrecl=200;
43 input;
44 call symputx('test3',_infile_);
45data _null_;
46 infile &out4 lrecl=200;
47 input;
48 call symputx('test4',_infile_);
49run;
50
51%mp_assert(
52 iftrue=("&test1" = "startsection"),
53 desc=Checking keep FIRST matchpoint START
54 outds=work.test_results
55)
56%mp_assert(
57 iftrue=("&test2" = "Chop here!endsection"),
58 desc=Checking keep LAST matchpoint START
59 outds=work.test_results
60)
61%mp_assert(
62 iftrue=("&test3" = "startsectionChop here!"),
63 desc=Checking keep FIRST matchpoint END
64 outds=work.test_results
65)
66%mp_assert(
67 iftrue=("&test4" = "endsection"),
68 desc=Checking keep LAST matchpoint END
69 outds=work.test_results
70)