The script uses the 'class' dataset from the SASHELP library. SASHELP is a standard SAS library, provided with any SAS installation, and therefore does not require external data or script-specific data creation for its execution.
1 Code Block
MACRO CALL
Explanation : Initializes a new SASUnit test scenario. This sets the global context for a series of related tests, facilitating the organization and reporting of test results.
Copied!
%initScenario (i_desc=Test of _existVar.sas);
1
%initScenario (i_desc=Test of _existVar.sas);
2 Code Block
MACRO CALL
Explanation : This block defines a test case to check for the presence of a numeric variable named 'age' in 'sashelp.class'. The `_existVar` macro is called with 'N' to specify a numeric type. The result is stored in `&rc.` and then compared to 1 (true) to confirm that the numeric variable 'age' indeed exists.
Copied!
%initTestcase(i_object=_existVar.sas, i_desc=Test for numeric variable age)
%let rc=%_existVar (sashelp.class
,age
,N
);
%endTestcall;
%assertEquals(i_expected=1, i_actual=&rc., i_desc=Numeric variable age exists)
%endTestcase;
1
%initTestcase(i_object=_existVar.sas, i_desc=Test for numeric variable age)
2
%let rc=%_existVar (sashelp.class
3
,age
4
,N
5
);
6
%endTestcall;
7
8
%assertEquals(i_expected=1, i_actual=&rc., i_desc=Numeric variable age exists)
9
%endTestcase;
3 Code Block
MACRO CALL
Explanation : This test case verifies that the 'age' variable is not recognized as a character type variable in 'sashelp.class'. The `_existVar` macro is called with 'C' for the character type. The expected result is 0 (false), confirming that 'age' is not a character variable, which is correct given that it is numeric in 'sashelp.class'.
Copied!
%initTestcase(i_object=_existVar.sas, i_desc=Test for character variable age)
%let rc=%_existVar (sashelp.class
,age
,C
);
%endTestcall;
%assertEquals(i_expected=0, i_actual=&rc., i_desc=Character variable age does not exist)
%endTestcase;
1
%initTestcase(i_object=_existVar.sas, i_desc=Test for character variable age)
2
%let rc=%_existVar (sashelp.class
3
,age
4
,C
5
);
6
%endTestcall;
7
8
%assertEquals(i_expected=0, i_actual=&rc., i_desc=Character variable age does not exist)
9
%endTestcase;
4 Code Block
MACRO CALL
Explanation : This block tests the existence of the 'name' variable in 'sashelp.class' without specifying a type. The `_existVar` macro is called without the type parameter. The expected result is 1 (true), which validates that the 'name' variable exists in the 'sashelp.class' dataset.
Copied!
%initTestcase(i_object=_existVar.sas, i_desc=Test for variable name)
%let rc=%_existVar (sashelp.class
,name
);
%endTestcall;
%assertEquals(i_expected=1, i_actual=&rc., i_desc=Variable name does not exist)
%endTestcase;
1
%initTestcase(i_object=_existVar.sas, i_desc=Test for variable name)
2
%let rc=%_existVar (sashelp.class
3
,name
4
);
5
%endTestcall;
6
7
%assertEquals(i_expected=1, i_actual=&rc., i_desc=Variable name does not exist)
8
%endTestcase;
5 Code Block
MACRO CALL
Explanation : Marks the end of the SASUnit test scenario. This means that all test cases associated with this scenario have been executed and the results can be compiled.
Copied!
%endScenario();
1
%endScenario();
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 : 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. For copyright information and terms of usage under the GNU Lesser General Public License see included file README.md or https://github.com/HMS-Analytical-Software/SASUnit/wiki/readme/.
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.