The script first defines the `dostuff` macro which accepts an `action` parameter. Depending on the value of `action` ('ADD', 'DEL', 'MOD', 'NOTHING'), the macro creates global variables, deletes them, modifies them, or does nothing. Then, the script executes a series of tests. Each test takes a 'snapshot' of the global macro variable environment with `%mp_assertscope(SNAPSHOT)`, executes `dostuff` with a specific action, then compares the new state with the initial snapshot using `%mp_assertscope(COMPARE, ...)`. Finally, `%mp_assert` is used to validate that the comparison report (stored in a work table) matches the expected result for each action (add, modify, delete, or no change).
Data Analysis
Type : INTERNAL_CREATION
The script does not read any source data. It dynamically generates work tables (work.testing_the_tester1, work.testing_the_tester2, etc.) as output of the `%mp_assertscope` test macro. These tables contain the comparison results of the macro variable environment before and after the execution of the `dostuff` macro.
1 Code Block
MACRO
Explanation : Definition of the 'dostuff' macro. It takes an 'action' parameter and can add ('ADD'), delete ('DEL'), or modify ('MOD') global macro variables (`NEWVAR1`, `NEWVAR2`). The 'NOTHING' action declares local variables for a test of no modification to the global environment.
Copied!
%macro dostuff(action);
%if &action=ADD %then %do;
%global NEWVAR1 NEWVAR2;
%end;
%else %if &action=DEL %then %do;
%symdel NEWVAR1 NEWVAR2;
%end;
%else %if &action=MOD %then %do;
%let NEWVAR1=Let us pray..;
%end;
%else %if &action=NOTHING %then %do;
%local a b c d e;
%end;
%mend dostuff;
1
%macro dostuff(ACTION);
2
%IF &ACTION=ADD %THEN %DO;
3
%global NEWVAR1 NEWVAR2;
4
%END;
5
%ELSE %IF &ACTION=DEL %THEN %DO;
6
%symdel NEWVAR1 NEWVAR2;
7
%END;
8
%ELSE %IF &ACTION=MOD %THEN %DO;
9
%let NEWVAR1=Let us pray..;
10
%END;
11
%ELSE %IF &ACTION=NOTHING %THEN %DO;
12
%local a b c d e;
13
%END;
14
%mend dostuff;
2 Code Block
MACRO Data
Explanation : This block tests variable addition. `%mp_assertscope(SNAPSHOT)` records the initial state of global variables. `%dostuff(ADD)` is called to create `NEWVAR1` and `NEWVAR2`. `%mp_assertscope(COMPARE)` compares the final state to the snapshot and writes the differences to `work.testing_the_tester1`. `%mp_assert` verifies that the test comment in the output table correctly indicates the addition of these two variables.
Copied!
/* check for adding variables */
%mp_assertscope(SNAPSHOT)
%dostuff(ADD)
%mp_assertscope(COMPARE,outds=work.testing_the_tester1)
%mp_assert(
iftrue=(
"%mf_getvalue(work.testing_the_tester1,test_comments)"
="Mod:() Add:(NEWVAR1 NEWVAR2) Del:()"
),
desc=Checking result when vars added,
outds=work.test_results
)
Explanation : This block tests variable modification. After the snapshot, `%dostuff(MOD)` modifies `NEWVAR1`. The `%mp_assert` macro validates that the comparison report (in `work.testing_the_tester2`) correctly reflects the modification of `NEWVAR1`.
Copied!
/* check for modifying variables */
%mp_assertscope(SNAPSHOT)
%dostuff(MOD)
%mp_assertscope(COMPARE,outds=work.testing_the_tester2)
%mp_assert(
iftrue=(
"%mf_getvalue(work.testing_the_tester2,test_comments)"
="Mod:(NEWVAR1) Add:() Del:()"
),
desc=Checking result when vars modified,
outds=work.test_results
)
Explanation : This block tests variable deletion. `%dostuff(DEL)` deletes `NEWVAR1` and `NEWVAR2`. The `%mp_assert` macro verifies that the comparison report (in `work.testing_the_tester3`) indicates the deletion of these two variables.
Copied!
/* check for deleting variables */
%mp_assertscope(SNAPSHOT)
%dostuff(DEL)
%mp_assertscope(COMPARE,outds=work.testing_the_tester3)
%mp_assert(
iftrue=(
"%mf_getvalue(work.testing_the_tester3,test_comments)"
="Mod:() Add:() Del:(NEWVAR1 NEWVAR2)"
),
desc=Checking result when vars deleted,
outds=work.test_results
)
Explanation : This block verifies that no changes are made to global variables. `%dostuff(NOTHING)` only declares local variables. The `%mp_assert` macro confirms that the comparison report (in `work.testing_the_tester4`) indicates that global variables were not modified.
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.
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.