generate_test.sas

Go to the documentation of this file.
00001  
00020 /*-- Testcase 1: one by variable ---------------------------------------------*/
00021 %initTestcase(i_object=generate.sas, i_desc=Example with one by variable)
00022 
00023 /* assign two temporary librefs */
00024 %_sasunit_mkdir(&g_work/test1)
00025 libname test1 "&g_work/test1";
00026 %_sasunit_mkdir(&g_work/test2)
00027 libname test2 "&g_work/test2";
00028 
00029 proc sort data=sashelp.class out=test2.class1 (label="Dataset for sex=F (9 observations)");
00030    by sex;
00031    where sex='F';
00032 run;
00033 proc sort data=sashelp.class out=test2.class2 (label="Dataset for sex=M (10 observations)");
00034    by sex;
00035    where sex='M';
00036 run;
00037    
00038 %generate(data=sashelp.class, by=sex, out=test1.class)
00039 %endTestcall()
00040 %assertLibrary(i_actual=test1, i_expected=test2, i_desc=check libraries)
00041 %endTestcase() /* assertLog is called implicitly */
00042 
00043 /*-- Testcase 2: two by variables --------------------------------------------*/
00044 %initTestcase(i_object=generate.sas, i_desc=Example with two by variables)
00045 proc datasets lib=test1 nolist kill;
00046 quit; 
00047 proc datasets lib=test2 nolist kill;
00048 quit; 
00049 proc sort data=sashelp.prdsale out=test2.prdsale1 (label="Dataset for region=EAST, year=1993 (360 observations)");
00050    by region year;
00051    where region="EAST" and year=1993;
00052 run;
00053 proc sort data=sashelp.prdsale out=test2.prdsale2 (label="Dataset for region=EAST, year=1994 (360 observations)");
00054    by region year;
00055    where region="EAST" and year=1994;
00056 run;
00057 proc sort data=sashelp.prdsale out=test2.prdsale3 (label="Dataset for region=WEST, year=1993 (360 observations)");
00058    by region year;
00059    where region="WEST" and year=1993;
00060 run;
00061 proc sort data=sashelp.prdsale out=test2.prdsale4 (label="Dataset for region=WEST, year=1994 (360 observations)");
00062    by region year;
00063    where region="WEST" and year=1994;
00064 run;
00065 %generate(data=sashelp.prdsale, by=region year, out=test1.prdsale)
00066 %endTestcall()
00067 %assertLibrary(i_actual=test1, i_expected=test2, i_desc=check libraries)
00068 %endTestcase() 
00069 
00070 /*-- Testcase 3: one by variable with only one value -------------------------*/
00071 %initTestcase(i_object=generate.sas, i_desc=Example with one by variable with only one value)
00072 proc datasets lib=test1 nolist kill;
00073 quit; 
00074 proc datasets lib=test2 nolist kill;
00075 quit; 
00076 /* create input dataset */
00077 proc sort data=sashelp.class out=class;
00078    by sex;
00079    where sex='F';
00080 run;
00081 /* create expected output dataset */
00082 proc sort data=sashelp.class out=test2.class1 (label="Dataset for sex=F (9 observations)");
00083    by sex;
00084    where sex='F';
00085 run;
00086 %generate(data=class, by=sex, out=test1.class)
00087 %endTestcall()
00088 %assertLibrary(i_actual=test1, i_expected=test2, i_desc=check libraries)
00089 %endTestcase() 
00090 
00091 /*-- Testcase 4: invalid dataset ---------------------------------------------*/
00092 %initTestcase(i_object=generate.sas, i_desc=invalid dataset)
00093 proc datasets lib=test1 nolist kill;
00094 quit; 
00095 proc datasets lib=test2 nolist kill;
00096 quit; 
00097 %generate(data=sashelp.classXXX, by=sex, out=test1.class)
00098 %endTestcall()
00099 %assertLogMsg(i_logMsg=ERROR: Macro Generate: data= or by= specified incorrectly)
00100 %endTestcase(i_assertLog=0)
00101 
00102 /*-- Testcase 5: invalid by variable -----------------------------------------*/
00103 %initTestcase(i_object=generate.sas, i_desc=invalid by variable)
00104 proc datasets lib=test1 nolist kill;
00105 quit; 
00106 proc datasets lib=test2 nolist kill;
00107 quit; 
00108 %generate(data=sashelp.class, by=sexXXX, out=test1.class)
00109 %endTestcall()
00110 %assertLogMsg(i_logMsg=ERROR: Macro Generate: data= or by= specified incorrectly)
00111 %endTestcase(i_assertLog=0)
00112 
00113 /*-- Testcase 6: invalid output library --------------------------------------*/
00114 %initTestcase(i_object=generate.sas, i_desc=invalid output library)
00115 proc datasets lib=test1 nolist kill;
00116 quit;    
00117 proc datasets lib=test2 nolist kill;
00118 quit; 
00119 %generate(data=sashelp.class, by=sex, out=test3.class)
00120 %endTestcall()
00121 %assertLogMsg(i_logMsg=ERROR: Libname TEST3 is not assigned)
00122 %endTestcase(i_assertLog=0)
00123 
00124 libname test1;
00125 libname test2;
00126 

Generated on Sun Oct 10 14:10:15 2010 for SASUnit Examples by  doxygen 1.5.3