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