%macro ProbChi( _chisq, _df, _retChiSq); /**************************************************************************************/ /* Name: ProbChi.sas Auth: Phil Rack */ /* Date: 5/16/2007 Revd: */ /* */ /* Desc: Returns the probability of a chi-squared distribution. */ /* */ /* Where: _chisq = is the chi-square value you want to test. */ /* _df = is the degrees of freedom. */ /* _retChiSq = The calculated Chi-Square Percentile (the returned value.) */ /* */ /* Copyright (C) 2007 by MineQuest, LLC. All Rights Reserved. www.minequest.com */ /**************************************************************************************/ IF (%length(%str(&_chisq)) eq 0) or (&_chisq = '.') OR (%length(%str(&_df)) eq 0) or (&_df = '.') THEN DO; &_retChiSq = .; END; Else DO; _r = 1; _v = &_df; do __i_ = _v to 2 by -2; _r = _r * __i_; end; *--> k = the numerator product; _k = &_chisq **(int(( _v + 1)/2)) * exp(- &_chisq / 2 )/ _r; *--> use the PI factor if DF is odd; if int( _v /2) ne _v /2 then _j=sqrt( 2 / &_ChiSq / 3.141592653599); else _j=1; _l = 1; _m = 1; do until (_m < .0000001); _v = _v + 2; _m = _m * &_chisq / _v; _l = _l + _m; End; &_retChiSq = (_j * _k * _l); drop _m _r _l _j _k _v __i_; END; /******************************************************************************************/ /* ProbChi is copyright (c) 2007 by MineQuest, LLC. All Rights Reserved. */ /* MineQuest, LLC, 1939 Queensbridge Dr., Columbus, OH USA. */ /* This Macro Program is proprietary software and is licensed property of MineQuest, LLC. */ /******************************************************************************************/ %mend ProbChi;