SASUnit Examples  Version 1.5.0
generate_test.sas
Go to the documentation of this file.
1 
26 /*-- Testcase 1: one by variable ---------------------------------------------*/
27 %initTestcase(i_object=generate.sas, i_desc=example with one by variable)
28 
29 /* assign two temporary librefs */
30 %_mkdir(&g_work/test1)
31 libname test1 "&g_work/test1";
32 %_mkdir(&g_work/test2)
33 libname test2 "&g_work/test2";
34 
35 proc sort data=sashelp.class out=test2.class1 (label="Dataset for sex=F (9 observations)");
36  by sex;
37  where sex='F';
38 run;
39 proc sort data=sashelp.class out=test2.class2 (label="Dataset for sex=M (10 observations)");
40  by sex;
41  where sex='M';
42 run;
43 
44 %generate(data=sashelp.class, by=sex, out=test1.class)
45 %endTestcall()
46 %assertLibrary(i_actual=test1, i_expected=test2, i_desc=check libraries)
47 %endTestcase() /* assertLog is called implicitly */
48 
49 /*-- Testcase 2: two by variables --------------------------------------------*/
50 %initTestcase(i_object=generate.sas, i_desc=example with two by variables)
51 proc datasets lib=test1 nolist kill;
52 quit;
53 proc datasets lib=test2 nolist kill;
54 quit;
55 proc sort data=sashelp.prdsale out=test2.prdsale1 (label="Dataset for region=EAST, year=1993 (360 observations)");
56  by region year;
57  where region="EAST" and year=1993;
58 run;
59 proc sort data=sashelp.prdsale out=test2.prdsale2 (label="Dataset for region=EAST, year=1994 (360 observations)");
60  by region year;
61  where region="EAST" and year=1994;
62 run;
63 proc sort data=sashelp.prdsale out=test2.prdsale3 (label="Dataset for region=WEST, year=1993 (360 observations)");
64  by region year;
65  where region="WEST" and year=1993;
66 run;
67 proc sort data=sashelp.prdsale out=test2.prdsale4 (label="Dataset for region=WEST, year=1994 (360 observations)");
68  by region year;
69  where region="WEST" and year=1994;
70 run;
71 %generate(data=sashelp.prdsale, by=region year, out=test1.prdsale)
72 %endTestcall()
73 %assertLibrary(i_actual=test1, i_expected=test2, i_desc=check libraries)
74 %endTestcase()
75 
76 /*-- Testcase 3: one by variable with only one value -------------------------*/
77 %initTestcase(i_object=generate.sas, i_desc=example with one by variable with only one value)
78 proc datasets lib=test1 nolist kill;
79 quit;
80 proc datasets lib=test2 nolist kill;
81 quit;
82 /* create input dataset */
83 proc sort data=sashelp.class out=class;
84  by sex;
85  where sex='F';
86 run;
87 /* create expected output dataset */
88 proc sort data=sashelp.class out=test2.class1 (label="Dataset for sex=F (9 observations)");
89  by sex;
90  where sex='F';
91 run;
92 %generate(data=class, by=sex, out=test1.class)
93 %endTestcall()
94 %assertLibrary(i_actual=test1, i_expected=test2, i_desc=check libraries)
95 %endTestcase()
96 
97 /*-- Testcase 4: invalid dataset ---------------------------------------------*/
98 %initTestcase(i_object=generate.sas, i_desc=invalid dataset)
99 proc datasets lib=test1 nolist kill;
100 quit;
101 proc datasets lib=test2 nolist kill;
102 quit;
103 %generate(data=sashelp.classXXX, by=sex, out=test1.class)
104 %endTestcall()
105 %assertLogMsg(i_logMsg=ERROR: Macro Generate: data= or by= specified incorrectly)
106 %endTestcase(i_assertLog=0)
107 
108 /*-- Testcase 5: invalid by variable -----------------------------------------*/
109 %initTestcase(i_object=generate.sas, i_desc=invalid by variable)
110 proc datasets lib=test1 nolist kill;
111 quit;
112 proc datasets lib=test2 nolist kill;
113 quit;
114 %generate(data=sashelp.class, by=sexXXX, out=test1.class)
115 %endTestcall()
116 %assertLogMsg(i_logMsg=ERROR: Macro Generate: data= or by= specified incorrectly)
117 %endTestcase(i_assertLog=0)
118 
119 /*-- Testcase 6: invalid output library --------------------------------------*/
120 %initTestcase(i_object=generate.sas, i_desc=invalid output library)
121 proc datasets lib=test1 nolist kill;
122 quit;
123 proc datasets lib=test2 nolist kill;
124 quit;
125 %generate(data=sashelp.class, by=sex, out=test3.class)
126 %endTestcall()
127 %assertLogMsg(i_logMsg=ERROR: (Libname|Libref) TEST3 is not assigned|ERROR: (Libname|Libref) TEST3 ist nicht zugewiesen
128  ,i_desc=regular expression used to support different languages
129  )
130 %endTestcase(i_assertLog=0)
131 
132 libname test1;
133 libname test2;
134