%macro lrtest(data, time, censor, xvar, var_to_test); %if "&var_to_test" ="" %then %do; data _null_; file print; put "There is no variable to be tested"; run; %goto exit; %end; /*end of if statement*/ %let varcount = 1; %let varname = %scan(&var_to_test, &varcount); %do %while ("&varname" ~=""); %let varcount =%eval(&varcount + 1); %let varname = %scan(&var_to_test, &varcount); %end; %let varcount = %eval(&varcount - 1); %if "&xvar"="" %then %do; /*comparing with the null model*/ ods listing close; ods output fitstatistics = rfit; proc phreg data = &data; model &time*&censor(0) = &var_to_test; run; ods listing; data _null_; file print; set rfit; if _n_ = 1 then do; p_value= put(1- probchi(withoutcovariates - withcovariates ,&varcount), F4.3); put "Full model: " "&var_to_test"; put "Test variables: " "&var_to_test " ; put "Degrees of freedom: " "&varcount" ; put "P value: " p_value ; end; run; %end; %else %do; ods listing close; ods output fitstatistics = rfit; proc phreg data = &data; model &time*&censor(0) = &xvar; run; ods output fitstatistics = fit; proc phreg data = &data; model &time*&censor(0) = &xvar &var_to_test; run; data _null_; set rfit; if _n_ = 1 then call symput('less', withcovariates); set fit; if _n_ = 1 then call symput('more', withcovariates); run; ods listing; data _null_; file print; p_value= put(1- probchi(&less - &more ,&varcount), F4.3); put "Full model: " "&xvar &var_to_test"; put "Reduced model: " "&xvar"; put "Test variables: " "&var_to_test" ; put "Degrees of freedom: " "&varcount" ; put "P value: " p_value ; run; %end; %exit: %mend lrtest;