SASUnit Examples  Version 1.5.0
assertrecordexists.sas
Go to the documentation of this file.
1 
26 %MACRO assertRecordExists (i_dataset =
27  ,i_whereExpr =
28  ,i_desc = Check for existence of specific records
29  );
30 
31  /*-- verify correct sequence of calls-----------------------------------------*/
32  %GLOBAL g_inTestcase;
33  %IF &g_inTestcase EQ 1 %THEN %DO;
34  %endTestcall;
35  %END;
36  %ELSE %IF &g_inTestcase NE 2 %THEN %DO;
37  %PUT &g_error.(SASUNIT): assert must be called after initTestcase;
38  %RETURN;
39  %END;
40 
41  %LOCAL l_countMatches l_rc l_errMsg;
42  %LET l_countMatches = -1;
43  %LET l_errMsg=;
44 
45  /*-- check parameter i_dataset ------------------------------------------------*/
46  %IF NOT %SYSFUNC(EXIST(&i_dataset.)) %THEN %DO;
47  %LET l_rc = 2;
48  %LET l_errMsg=input dataset &i_dataset. does not exist!;
49  %GOTO Update;
50  %END;
51 
52  /*-- check parameter i_dataset ------------------------------------------------*/
53  %IF %LENGTH(&i_whereExpr) = 0 %THEN %DO;
54  %LET l_rc = 2;
55  %LET l_errMsg=where expression is empty!;
56  %GOTO Update;
57  %END;
58 
59  PROC SQL NOPRINT;
60  SELECT COUNT(*) FORMAT=best12. INTO :l_countMatches
61  FROM &i_dataset(WHERE=(%nrbquote(&i_whereExpr)))
62  ;
63  QUIT;
64 
65  %LET l_countMatches = &l_countMatches; /* trim white space */
66 
67  %IF %eval(&l_countMatches >= 1)
68  %THEN %LET l_rc = 0;
69  %ELSE
70  %LET l_rc = 2;
71  %LET l_errMsg=No matching records were found!;
72 
73 %UPDATE:
74  /*-- update comparison result in test database -------------------------------*/
75  %_asserts(i_type = assertRecordExists
76  ,i_expected = > 0
77  ,i_actual = &l_countMatches.
78  ,i_desc = &i_desc.
79  ,i_result = &l_rc.
80  ,i_errMsg = &l_errMsg.
81  );
82 
83 %MEND assertRecordExists;