SASUnit Examples  Version 1.2.1
boxplot_test.sas
Go to the documentation of this file.
1 
24 /* History
25  05.10.2010 AM Changed output format to pdf in order to be able to run on linux
26 */
27 
28 /*-- standard case without reference -----------------------------------------*/
29 %initTestcase(i_object=boxplot.sas, i_desc=standard case without reference)
30 %boxplot(data=testdata.blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report1.pdf)
31 %assertReport(i_actual=&g_work\report1.pdf, i_expected=,
32  i_desc=please compare chart with specification in source code)
33 
34 /*-- standard case with reference --------------------------------------------*/
35 %initTestcase(i_object=boxplot.sas, i_desc=standard case with reference)
36 %boxplot(data=testdata.blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report2.pdf)
37 %assertReport(i_actual=&g_work\report2.pdf, i_expected=&g_refdata\boxplot1.pdf,
38  i_desc=please compare the two charts)
39 
40 /*-- standard case with reference, missing values for Y ----------------------*/
41 %initTestcase(i_object=boxplot.sas, i_desc=%str(standard case with reference, missing values for Y ))
42 data blood_pressure;
43  set testdata.blood_pressure;
44  output;
45  sbp=.;
46  output;
47 run;
48 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report3.pdf)
49 %assertReport(i_actual=&g_work\report3.pdf, i_expected=&g_refdata\boxplot1.pdf,
50  i_desc=%str(please compare the two charts, no changes produced by missing values in the y variable))
51 %assertLogMsg(i_logMsg=%str(NOTE: 240 observation\(s\) contained a MISSING value for the SBP \* Visit = Med request|NOTE: 240 Beobachtung\(en\) in fehlendem Wert enthalten für den Befehl SBP \* Visit = Med)
52  ,i_desc=regular expression used to support different languages
53  )
54 
55 /*-- different scaling for x and y axis --------------------------------------*/
56 %initTestcase(i_object=boxplot.sas, i_desc=different scaling for x and y axis)
57 data blood_pressure;
58  set testdata.blood_pressure;
59  visit=visit*100;
60  sbp=sbp*100;
61 run;
62 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report4.pdf)
63 %assertReport(i_actual=&g_work\report4.pdf, i_expected=,
64  i_desc=please compare chart with specification in source code)
65 
66 /*-- only two visits ---------------------------------------------------------*/
67 %initTestcase(i_object=boxplot.sas, i_desc=only two visits)
68 data blood_pressure;
69  set testdata.blood_pressure;
70  where visit in (1, 5);
71 run;
72 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report5.pdf)
73 %assertReport(i_actual=&g_work\report5.pdf, i_expected=,
74  i_desc=please compare chart with specification in source code)
75 
76 /*-- Error: only one visit ---------------------------------------------------*/
77 %initTestcase(i_object=boxplot.sas, i_desc=only one visit)
78 data blood_pressure;
79  set testdata.blood_pressure;
80  where visit in (3);
81 run;
82 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report6.pdf)
83 %assertLogMsg(i_logMsg=ERROR: boxplot: x variable must have at least two values)
84 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report6.pdf)), i_expected=0, i_desc=no report created)
85 %endTestcase(i_assertLog=0)
86 
87 /*-- 18 visits ---------------------------------------------------------------*/
88 %initTestcase(i_object=boxplot.sas, i_desc=18 visits)
89 data blood_pressure;
90  set
91  testdata.blood_pressure (in=in1)
92  testdata.blood_pressure (in=in2)
93  testdata.blood_pressure (in=in3)
94  ;
95  if in2 then visit=visit+6;
96  if in3 then visit=visit+12;
97 run;
98 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report7.pdf)
99 %assertReport(i_actual=&g_work\report7.pdf, i_expected=,
100  i_desc=please compare chart with specification in source code)
101 
102 /*-- Error: invalid input data set -------------------------------------------*/
103 %initTestcase(i_object=boxplot.sas, i_desc=invalid input data set)
104 %boxplot(data=XXXXX, x=visit, y=sbp, group=med, report=&g_work\report8.pdf)
105 %assertLogMsg(i_logMsg=ERROR: boxplot: Data set XXXXX does not exist)
106 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report8.pdf)), i_expected=0, i_desc=no report created)
107 %endTestcase(i_assertLog=0)
108 
109 /*-- Error: input data set missing -------------------------------------------*/
110 %initTestcase(i_object=boxplot.sas, i_desc=input data set missing)
111 %boxplot(data=, x=visit, y=sbp, group=med, report=&g_work\report9.pdf)
112 %assertLogMsg(i_logMsg=ERROR: boxplot: Data set does not exist)
113 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report9.pdf)), i_expected=0, i_desc=no report created)
114 %endTestcase(i_assertLog=0)
115 
116 /*-- Error: invalid x variable -----------------------------------------------*/
117 %initTestcase(i_object=boxplot.sas, i_desc=invalid x variable)
118 %boxplot(data=testdata.blood_pressure, x=visitXXX, y=sbp, group=med, report=&g_work\report10.pdf)
119 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable visitXXX does not exist in data set testdata.blood_pressure)
120 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report10.pdf)), i_expected=0, i_desc=no report created)
121 %endTestcase(i_assertLog=0)
122 
123 /*-- Error: x variable missing -----------------------------------------------*/
124 %initTestcase(i_object=boxplot.sas, i_desc=x variable missing)
125 %boxplot(data=testdata.blood_pressure, x=, y=sbp, group=med, report=&g_work\report11.pdf)
126 %assertLogMsg(i_logMsg=ERROR: boxplot: X variable not specified)
127 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report11.pdf)), i_expected=0, i_desc=no report created)
128 %endTestcase(i_assertLog=0)
129 
130 /*-- Error: x variable not numeric -------------------------------------------*/
131 %initTestcase(i_object=boxplot.sas, i_desc=x variable not numeric)
132 data blood_pressure;
133  set testdata.blood_pressure;
134  visitc = put (visit, 1.);
135 run;
136 %boxplot(data=blood_pressure, x=visitc, y=sbp, group=med, report=&g_work\report12.pdf)
137 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable visitc in data set blood_pressure must be numeric)
138 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report12.pdf)), i_expected=0, i_desc=no report created)
139 %endTestcase(i_assertLog=0)
140 
141 /*-- Error: x variable values not equidistant --------------------------------*/
142 %initTestcase(i_object=boxplot.sas, i_desc=x variable values not equidistant)
143 data blood_pressure;
144  set testdata.blood_pressure;
145  if visit=5 then visit=6;
146 run;
147 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report13.pdf)
148 %assertLogMsg(i_logMsg=ERROR: boxplot: Values of x variable are not equidistant)
149 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report13.pdf)), i_expected=0, i_desc=no report created)
150 %endTestcase(i_assertLog=0)
151 
152 /*-- Error: x variable has missing values ------------------------------------*/
153 %initTestcase(i_object=boxplot.sas, i_desc=x variable has missing values)
154 data blood_pressure;
155  set testdata.blood_pressure;
156  output;
157  visit=.;
158  output;
159 run;
160 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report14.pdf)
161 %assertLogMsg(i_logMsg=ERROR: boxplot: Missing values in x variable are not allowed)
162 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report14.pdf)), i_expected=0, i_desc=no report created)
163 %endTestcase(i_assertLog=0)
164 
165 /*-- Error: invalid y variable -----------------------------------------------*/
166 %initTestcase(i_object=boxplot.sas, i_desc=invalid y variable)
167 %boxplot(data=testdata.blood_pressure, x=visit, y=sbpXXX, group=med, report=&g_work\report15.pdf)
168 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable sbpXXX does not exist in data set testdata.blood_pressure)
169 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report15.pdf)), i_expected=0, i_desc=no report created)
170 %endTestcase(i_assertLog=0)
171 
172 /*-- Error: y variable not specified -----------------------------------------*/
173 %initTestcase(i_object=boxplot.sas, i_desc=y variable not specified)
174 %boxplot(data=testdata.blood_pressure, x=visit, y=, group=med, report=&g_work\report16.pdf)
175 %assertLogMsg(i_logMsg=ERROR: boxplot: Y variable not specified)
176 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report16.pdf)), i_expected=0, i_desc=no report created)
177 %endTestcase(i_assertLog=0)
178 
179 /*-- Error: y variable not numeric -------------------------------------------*/
180 %initTestcase(i_object=boxplot.sas, i_desc=y variable not numeric)
181 data blood_pressure;
182  set testdata.blood_pressure;
183  sbpc = put (sbp, best32.);
184 run;
185 %boxplot(data=blood_pressure, x=visit, y=sbpc, group=med, report=&g_work\report17.pdf)
186 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable sbpc in data set blood_pressure must be numeric)
187 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report17.pdf)), i_expected=0, i_desc=no report created)
188 %endTestcase(i_assertLog=0)
189 
190 /*-- Error: invalid group variable -------------------------------------------*/
191 %initTestcase(i_object=boxplot.sas, i_desc=invalid group variable)
192 %boxplot(data=testdata.blood_pressure, x=visit, y=sbp, group=medXXX, report=&g_work\report18.pdf)
193 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable medXXX does not exist in data set testdata.blood_pressure)
194 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report18.pdf)), i_expected=0, i_desc=no report created)
195 %endTestcase(i_assertLog=0)
196 
197 /*-- Error: group variable not specified -------------------------------------*/
198 %initTestcase(i_object=boxplot.sas, i_desc=group variable not specified)
199 %boxplot(data=testdata.blood_pressure, x=visit, y=sbp, group=, report=&g_work\report19.pdf)
200 %assertLogMsg(i_logMsg=ERROR: boxplot: Group variable not specified)
201 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report19.pdf)), i_expected=0, i_desc=no report created)
202 %endTestcase(i_assertLog=0)
203 
204 /*-- Error: group variable has only one value --------------------------------*/
205 %initTestcase(i_object=boxplot.sas, i_desc=group variable has only one value)
206 data blood_pressure;
207  set testdata.blood_pressure;
208  if med=1;
209 run;
210 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report20.pdf)
211 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable med must have exactly two values)
212 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report20.pdf)), i_expected=0, i_desc=no report created)
213 %endTestcase(i_assertLog=0)
214 
215 /*-- Error: group variable has more than two values -------------------------*/
216 %initTestcase(i_object=boxplot.sas, i_desc=group variable has more than two values)
217 data blood_pressure2;
218  set testdata.blood_pressure;
219  if med=1 then do;
220  output;
221  med=2;
222  output;
223  end;
224  else output;
225 run;
226 %boxplot(data=blood_pressure2, x=visit, y=sbp, group=med, report=&g_work\report21.pdf)
227 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable med must have exactly two values)
228 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report21.pdf)), i_expected=0, i_desc=no report created)
229 %endTestcase(i_assertLog=0)
230 
231 /*-- Error: group variable has missing values --------------------------------*/
232 %initTestcase(i_object=boxplot.sas, i_desc=group variable has missing values)
233 data blood_pressure3;
234  set testdata.blood_pressure;
235  if med=0 then do;
236  med=.;
237  output;
238  end;
239 run;
240 %boxplot(data=blood_pressure3, x=visit, y=sbp, group=med, report=&g_work\report22.pdf)
241 %assertLogMsg(i_logMsg=ERROR: boxplot: Missing values in group variable are not allowed)
242 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report22.pdf)), i_expected=0, i_desc=no report created)
243 %endTestcase(i_assertLog=0)
244