The script creates a temporary directory structure and SAS dataset for testing purposes. No external data or data from the `SASHELP` library is used directly for the testing process. Test data is generated in place.
1 Code Block
MACRO mf_mkdir / DATA STEP Data
Explanation : This code block initializes a macro variable `root` pointing to a new 'top' subdirectory in the temporary work directory (`work`). It then repeatedly uses the `%mf_mkdir` macro to create a nested directory hierarchy. A `test` libname is defined to point to the deepest directory. Finally, a `ds1` dataset is created in this library, serving as test data.
Copied!
%let root=%sysfunc(pathname(work))/top;
%mf_mkdir(&root)
%mf_mkdir(&root/a)
%mf_mkdir(&root/b)
%mf_mkdir(&root/a/d)
%mf_mkdir(&root/a/e)
%mf_mkdir(&root/a/e/f)
libname test '&root/a/e/f';
data test.ds1;
x=1;
run;
1
%let root=%sysfunc(pathname(work))/top;
2
%mf_mkdir(&root)
3
%mf_mkdir(&root/a)
4
%mf_mkdir(&root/b)
5
%mf_mkdir(&root/a/d)
6
%mf_mkdir(&root/a/e)
7
%mf_mkdir(&root/a/e/f)
8
LIBNAME test '&root/a/e/f';
9
DATA test.ds1;
10
x=1;
11
RUN;
2 Code Block
MACRO mp_dirlist / MACRO mp_assert
Explanation : This block tests the `%mp_dirlist` macro by asking it to list all directory levels under `&root` (with `maxdepth=MAX`). The `%mf_nobs` macro is used to count observations in the output dataset `work.myTable`. `%mp_assert` verifies that the number of observations is equal to 6, which corresponds to the total number of directories created.
Explanation : This test calls `%mp_dirlist` with `maxdepth=2`, meaning that only directories from the first two depth levels (from `&root`) should be listed. `%mp_assert` is used to confirm that the `work.myTable2` dataset contains 5 observations, thus validating the depth limitation.
Explanation : This code block tests `%mp_dirlist` with `maxdepth=0`, indicating that only the specified directory (`&root`) itself should be returned. `%mp_assert` verifies that the `work.myTable3` dataset contains 2 observations, which is the expected behavior for this listing depth (generally the directory itself plus an entry for metadata or the parent).
Explanation : This test validates the behavior of `%mp_dirlist` when applied to an empty directory (`&root/b`). The `%mp_assert` macro is used to verify that the output dataset `work.myTable4` contains no observations, as expected for a directory with no subdirectories or listable files.
Explanation : The last code block tests `%mp_dirlist` with a non-existent directory path (`&root/notexisting`). `%mp_assert` is used to confirm that the `work.myTable5` output dataset is empty, indicating that the macro correctly handles invalid paths without generating an error and by returning an empty result.
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 use under the GNU Lesser General Public License, see the included README.md file 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.