SPSS Syntax of Running Cox Regression with Time-Varying Covariates

SPSS Syntax of Running Cox Regression with Time-Varying Covariates

Chapter 6: SAS Syntax to Run LWA & WLW

Because concerns about protecting human subjects, I cannot release the data with study children’s sibling group ID and individual ID, which are the main variables to run multilevel survival analysis. However, the following syntax shows how to run LWA and WLW models with SAS.

SAS Syntax Running LWA using SAS 8.2

libname demo2 'd:\adv eha';

data data1;

set demo2.repeat;

procphregdata=data1 covs(aggregate);

model los*event(0) = age boy black resi;

id id;

run;

SAS Syntax Running WLW Macro

/* Cox Regression using WLW Macro */

libname demo2 'd:\adv eha';

data data1;

set demo2.repeat;

procmeans;

%inc'd:\adv eha\wlw.sas' /nosource;

%wlw(dv=los*event(0),cv=age boy black resi,

evcnt=j,id=id,max=3,data=data1,ties=efron);

run;

WLW Macro [Written by Allison (1995), downloaded from SAS website]

In the above example, WLW.SAS is saved in the subdirectory d:\adv eha

%macro wlw(dv=,cv=, evcnt=,id=,max=,data=_last_,ties=efron);

/*Preliminary operations on parameter specifications*/

%do i = 1 %to 20;

%let var&i=%scan(&cv,&i);

%if &var&i = %then %goto out;

%if %length(&var&i) > 6 %then %let vv&i=%substr(&var&i,1,6);

%else %let vv&i=&var&i;

%end;

%out: %let i=%eval(&i-1);

%let tot=%eval(&i*&max);

%do j=1 %to &i;

%let vdef&j=arr&j(_i_) = &var&j*(evcnt=_i_);

%let cvd&j= &vv&j..1-&vv&j..&max;

%let ar&j=array arr&j(*) &vv&j..1-&vv&j..&max;

%end;

/*Create data set with covariate by time interactions*/

data expand;

ncv=&i;

set &data;

evcnt=&evcnt;

%do j=1 %to &i;

&ar&j;

%end;

do _i_ = 1 to &max;

%do j=1 %to &i;

&vdef&j;

%end;

end;

run;

/*Do PHREG model for all events*/

proc phreg data=expand outest=_a_ noprint;

model &dv=

%do j=1 %to &i;

&cvd&j

%end;

/ties=&ties;

output out=_out1_ dfbeta=dt1-dt&tot/order=data;

id &id;

strata &evcnt;

run;

/*Sum the DFBETA statistics*/

proc sort data=_out1_;

by &id; run;

proc means data=_out1_ noprint;

by &id;

var dt1-dt&tot;

output out=_out2_(drop=&id _type_ _freq_) sum=dt1-dt&tot;

/*Calculate the robust covariance matrix, perform tests*/

proc iml;

names={&cv};

nvar=ncol(names);

use _a_;

read all var _num_ into b;

b= b`;

use _out2_;

read all into x;

do i=1 to nvar;

stop=i*&max;

start=stop-&max+1;

bi= b[start:stop];

xi=x[,start:stop];

v= xi` * xi;

iv=inv(v);

se=sqrt(vecdiag(v));

reset noname;

cname= {"Estimate", " Std Error"};

cname2={"Event"};

indx= (1:&max)`;

tmpprt= bi || se;

print / "Results For" (names[i]);

print indx[colname=cname2] tmpprt[colname=cname format=10.5];

print "Estimated Joint Covariance Matrix",, v;

/* H0: All coefficients equal to 0 */

chisq= bi` * iv * bi;

df= nrow(bi);

p= 1-probchi(chisq,df);

print ,,"Testing H0: no treatment effects for" (names[i]), ,

"Wald Chi-Square = " chisq, "DF = " df,

"p-value = "p[format=5.4],;

/* H0: All coefficients equal to each other */

c=j(df-1,df,0);

do k=1 to df-1;

c[k,k]=1;

c[k,k+1]=-1;

end;

chisq= bi`*c`*inv(c*v*c`)*c * bi;

df= df-1;

p= 1-probchi(chisq,df);

print ,,"Testing H0:Equal Coefficients for" (names[i]), ,

"Wald Chi-Square = " chisq, "DF = " df,

"p-value = "p[format=5.4],;

/* Assume coefficients equal. Estimate the common value */

nparm=nrow(bi);

e= j(nparm,1,1);

h= inv(e` * iv * e) * iv * e;

b1= h` * bi;

se= sqrt(h` * v * h);

zscore= b1 / se;

p= 1- probchi( zscore * zscore, 1);

print ,,"Estimation of the Common Parameter for" (names[i]),,

"optimal weights = "h,

"Estimate = " b1,

"Standard Error = " se,

"z-score =" zscore,

"2-sided p-value = " p[format=5.4];

end;

quit;

run;

%mend wlw;

SAS Syntax for “LWA & WLW” Page 1