The script uses the `sashelp.class` table, which is a standard example table provided with SAS, as a data source for the `mf_getvarlist` macro. No external data is required, and all test data is generated or comes from SASHELP. Test results are then stored in the internal `work.test_results` table.
1 Code Block
Macro calls
Explanation : This code block makes several calls to the `%mf_getvarlist` macro. Each call uses the `sashelp.class` table as input and varies the options for the delimiter (`dlm`) and filtering by variable type (`typefilter`). The results (variable name lists) are stored in macro variables (`test1` to `test5`) for later evaluation.
Explanation : This `DATA STEP` block creates the `work.test_results` table to record test results. For each test case, it retrieves the value of the corresponding macro variable (containing the list of variables extracted by `%mf_getvarlist`) via `symget()`. It then compares this value to a predefined `result` string that represents the expected outcome. A 'PASS' or 'FAIL' status is assigned based on this comparison, and detailed comments are recorded. The temporary variables `base` and `result` are then dropped.
Copied!
data work.test_results;
length test_description $256 test_result $4 test_comments base result $256;
test_description="Basic test";
base=symget('test1');
result='Name Sex Age Height Weight';
if base=result then test_result='PASS';
else test_result='FAIL';
test_comments="Comparing "!!trim(base)!!' vs '!!trim(result);
output;
test_description="DLM test";
base=symget('test2');
result='NameXSexXAgeXHeightXWeight';
if base=result then test_result='PASS';
else test_result='FAIL';
test_comments="Comparing "!!trim(base)!!' vs '!!trim(result);
output;
test_description="DLM + quote test";
base=symget('test3');
result='"Name","Sex","Age","Height","Weight"';
if base=result then test_result='PASS';
else test_result='FAIL';
test_comments="Comparing "!!trim(base)!!' vs '!!trim(result);
output;
test_description="Numeric Filter";
base=symget('test4');
result='Age Height Weight';
if base=result then test_result='PASS';
else test_result='FAIL';
test_comments="Comparing "!!trim(base)!!' vs '!!trim(result);
output;
test_description="Char Filter";
base=symget('test5');
result='Name Sex';
if base=result then test_result='PASS';
else test_result='FAIL';
test_comments="Comparing "!!trim(base)!!' vs '!!trim(result);
output;
drop base result;
run;
1
DATA work.test_results;
2
LENGTH test_description $256 test_result $4 test_comments base RESULT $256;
3
test_description="Basic test";
4
base=symget('test1');
5
RESULT='Name Sex Age Height Weight';
6
IF base=RESULTTHEN test_result='PASS';
7
ELSE test_result='FAIL';
8
test_comments="Comparing "!!trim(base)!!' vs '!!trim(RESULT);
9
OUTPUT;
10
11
test_description="DLM test";
12
base=symget('test2');
13
RESULT='NameXSexXAgeXHeightXWeight';
14
IF base=RESULTTHEN test_result='PASS';
15
ELSE test_result='FAIL';
16
test_comments="Comparing "!!trim(base)!!' vs '!!trim(RESULT);
17
OUTPUT;
18
19
test_description="DLM + quote test";
20
base=symget('test3');
21
RESULT='"Name","Sex","Age","Height","Weight"';
22
IF base=RESULTTHEN test_result='PASS';
23
ELSE test_result='FAIL';
24
test_comments="Comparing "!!trim(base)!!' vs '!!trim(RESULT);
25
OUTPUT;
26
27
test_description="Numeric Filter";
28
base=symget('test4');
29
RESULT='Age Height Weight';
30
IF base=RESULTTHEN test_result='PASS';
31
ELSE test_result='FAIL';
32
test_comments="Comparing "!!trim(base)!!' vs '!!trim(RESULT);
33
OUTPUT;
34
35
test_description="Char Filter";
36
base=symget('test5');
37
RESULT='Name Sex';
38
IF base=RESULTTHEN test_result='PASS';
39
ELSE test_result='FAIL';
40
test_comments="Comparing "!!trim(base)!!' vs '!!trim(RESULT);
41
OUTPUT;
42
43
drop base RESULT;
44
RUN;
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.