Datasets 'test1' and 'test2' are created internally within the script to simulate different test scenarios. Dataset 'test3' is intentionally non-existent to test a boundary case.
1 Code Block
DATA STEP Data
Explanation : This DATA STEP block creates a temporary dataset named 'test1' which contains 100 observations. It serves as reference data for a standard observation count test.
Copied!
data test1;
do i=1 to 100;
output;
end;
run;
1
DATA test1;
2
DO i=1 to 100;
3
OUTPUT;
4
END;
5
RUN;
2 Code Block
Macro SASUnit
Explanation : This block executes a SASUnit test case. It calls the '%_nobs' macro on the 'test1' dataset and uses '%assertEquals' to verify that the returned number of observations is 100, as expected. '%assertLog()' checks that no unexpected errors are present in the SAS log.
Copied!
%initTestcase(i_object=_nobs.sas, i_desc=standard case with 100 obs)
%LET g_nobs = %_nobs(test1);
%assertEquals(i_expected=100, i_actual=&g_nobs, i_desc=number of observations must be 100)
%assertLog()
%endTestcase()
1
%initTestcase(i_object=_nobs.sas, i_desc=standard case with 100 obs)
2
%LET g_nobs = %_nobs(test1);
3
%assertEquals(i_expected=100, i_actual=&g_nobs, i_desc=number of observations must be 100)
4
%assertLog()
5
%endTestcase()
3 Code Block
DATA STEP Data
Explanation : This DATA STEP block creates a temporary dataset named 'test2' which is intentionally empty (0 observations). It is used to test the behavior of the '_nobs' macro with a dataset containing no observations.
Copied!
data test2;
stop;
run;
1
DATA test2;
2
stop;
3
RUN;
4 Code Block
Macro SASUnit
Explanation : This test block verifies the '%_nobs' macro with the empty 'test2' dataset. It expects the macro to return 0 observations, which is validated by '%assertEquals'.
Copied!
%initTestcase(i_object=_nobs.sas, i_desc=dataset with 0 obs)
%LET g_nobs = %_nobs(test2);
%assertEquals(i_expected=0, i_actual=&g_nobs, i_desc=number of observations must be 0)
%assertLog()
1
%initTestcase(i_object=_nobs.sas, i_desc=dataset with 0 obs)
2
%LET g_nobs = %_nobs(test2);
3
%assertEquals(i_expected=0, i_actual=&g_nobs, i_desc=number of observations must be 0)
4
%assertLog()
5 Code Block
Macro SASUnit
Explanation : This test block evaluates the behavior of the '%_nobs' macro when called with a dataset ('test3') that does not exist. The '%assertEquals' assertion verifies that the macro handles this case by returning 0 observations.
Copied!
%initTestcase(i_object=_nobs.sas, i_desc=dataset not existing)
%LET g_nobs = %_nobs(test3);
%assertEquals(i_expected=0, i_actual=&g_nobs, i_desc=number of observations must be 0)
%assertLog()
%endTestcase;
1
%initTestcase(i_object=_nobs.sas, i_desc=dataset not existing)
2
%LET g_nobs = %_nobs(test3);
3
%assertEquals(i_expected=0, i_actual=&g_nobs, i_desc=number of observations must be 0)
4
%assertLog()
5
%endTestcase;
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.