The script begins by defining macro variables for temporary file paths and the matching string. It then creates a temporary text file (`file.txt`) in the WORK library with predefined content. The `%mp_chop` macro is called four times, each call testing a specific combination of parameters to split the input file and save the results into distinct output files. The `%mp_assertscope` macros are used for test context management. After `%mp_chop` execution, the script reads the content of each output file into macro variables and uses the `%mp_assert` macro (part of the SASUnit framework) to validate that the splitting results match expectations for each test scenario.
Data Analysis
Type : INTERNAL_CREATION
The input data (`file.txt`) is entirely created and managed within the script itself, in the temporary WORK library, via a DATA _NULL_ step. The output files produced by %mp_chop are also temporary, and their contents are read internally for test verification.
1 Code Block
Macro-variable definition
Explanation : This block initializes macro variables essential to the script, defining the temporary input file name, the character string to search for, and the names of the four output files that will contain the results of the %mp_chop macro.
Explanation : Creates a temporary text file (`file.txt`) in the WORK library. This file serves as the input dataset for testing the %mp_chop macro, with simple content to verify splitting operations.
Copied!
data _null_;
file &src;
put "startsection&str.endsection";
run;
1
DATA _null_;
2
file &src;
3
put "startsection&str.endsection";
4
RUN;
3 Code Block
Macro call Data
Explanation : This block executes the %mp_chop macro four times, testing different combinations of parameters (retaining the 'FIRST' or 'LAST' part, and 'START' or 'END' match point). Each call writes the result to a distinct temporary file. `%mp_assertscope` is used to manage the test environment, probably to save and restore the state of macro variables.
Explanation : This series of DATA _NULL_ steps reads the content of each of the four output files generated by %mp_chop and stores the first line of each file in dedicated macro variables (`test1` to `test4`). These macro variables will be used for result verification.
Copied!
data _null_;
infile &out1 lrecl=200;
input;
call symputx('test1',_infile_);
data _null_;
infile &out2 lrecl=200;
input;
call symputx('test2',_infile_);
data _null_;
infile &out3 lrecl=200;
input;
call symputx('test3',_infile_);
data _null_;
infile &out4 lrecl=200;
input;
call symputx('test4',_infile_);
run;
1
DATA _null_;
2
INFILE &out1 lrecl=200;
3
INPUT;
4
call symputx('test1',_infile_);
5
DATA _null_;
6
INFILE &out2 lrecl=200;
7
INPUT;
8
call symputx('test2',_infile_);
9
DATA _null_;
10
INFILE &out3 lrecl=200;
11
INPUT;
12
call symputx('test3',_infile_);
13
DATA _null_;
14
INFILE &out4 lrecl=200;
15
INPUT;
16
call symputx('test4',_infile_);
17
RUN;
5 Code Block
Macro call
Explanation : This block uses the `%mp_assert` macro to perform four distinct assertions. Each assertion checks if the content of a macro variable (derived from the output files of %mp_chop) matches the expected character string. The descriptions (`desc`) and the output dataset for the test results (`outds=work.test_results`) are specified for each assertion, documenting the different test scenarios.
Copied!
%mp_assert(
iftrue=("&test1" = "startsection"),
desc=Checking keep FIRST matchpoint START
outds=work.test_results
)
%mp_assert(
iftrue=("&test2" = "Chop here!endsection"),
desc=Checking keep LAST matchpoint START
outds=work.test_results
)
%mp_assert(
iftrue=("&test3" = "startsectionChop here!"),
desc=Checking keep FIRST matchpoint END
outds=work.test_results
)
%mp_assert(
iftrue=("&test4" = "endsection"),
desc=Checking keep LAST matchpoint END
outds=work.test_results
)
1
%mp_assert(
2
iftrue=("&test1" = "startsection"),
3
desc=Checking keep FIRST matchpoint START
4
outds=work.test_results
5
)
6
%mp_assert(
7
iftrue=("&test2" = "Chop here!endsection"),
8
desc=Checking keep LAST matchpoint START
9
outds=work.test_results
10
)
11
%mp_assert(
12
iftrue=("&test3" = "startsectionChop here!"),
13
desc=Checking keep FIRST matchpoint END
14
outds=work.test_results
15
)
16
%mp_assert(
17
iftrue=("&test4" = "endsection"),
18
desc=Checking keep LAST matchpoint END
19
outds=work.test_results
20
)
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : The script references and uses macros from the SASUnit framework. SASUnit copyright is: Copyright 2010-2023 HMS Analytical Software GmbH, http://www.analytical-software.de. This file is part of SASUnit, the unit testing framework for SAS(R) programs.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.