SASUnit Examples  Version 1.5.0
regression_test.sas
Go to the documentation of this file.
1 
26 /*-- Compare linear regression between Excel and SAS -------------------------*/
27 
28 %initTestcase(i_object=regression.sas, i_desc=compare linear regression between Excel and SAS)
29 %macro SetXLSType;
30  %if (&sysver=9.1) %then EXCEL; %else XLS;
31 %mend;
32 proc import datafile="&g_testdata/regression.xls" dbms=%SetXLSType out=work.data replace;
33  RANGE="data";
34 run;
35 data refdata (rename=(yhat=est)) testdata(drop=yhat);
36  set work.data;
37  format _all_;
38 run;
39 proc import datafile="&g_testdata/regression.xls" dbms=%SetXLSType out=refparm replace;
40  RANGE="parameters";
41 run;
42 
43 %regression(data=testdata, x=x, y=y, out=aus, yhat=est, parms=parameters, report=&g_work/report1.rtf)
44 
45 proc sql noprint;
46  select intercept into :intercept_sas from parameters;
47  select put (x, best12.) into :slope_sas from parameters;
48  select put (e, best12.) into :slope_xls from refparm;
49  select f into :intercept_xls from refparm;
50 quit;
51 
52 %assertReport(i_actual=&g_work/report1.rtf, i_expected=&g_testdata/regression.xls,
53  i_desc=please compare SAS chart with Excel chart)
54 
55 %assertColumns(i_actual=aus, i_expected=refdata, i_desc=compare estimated values, i_fuzz=1E-10)
56 
57 %assertEquals(i_actual=&intercept_xls, i_expected=&intercept_sas, i_desc=compare intercept parameter)
58 %assertEquals(i_actual=&slope_xls, i_expected=&slope_sas, i_desc=compare slope parameter)
59 %assertPerformance(i_expected=5, i_desc=regression calculation should be done within 5 seconds.)
60