SAS 生存分析

/*--------------------生存分析--------------------*/

/*------寿命表法-----*/
data sc;
	input lt@@;                 /*输入变量lt*/
	if lt<0 then censor=1;      /*若lt小于0(代表数据删失),则变量censor赋值为1,否则,赋值为0*/
	else censor=0;
	if _n_<16 then group='high-wbc';  /*组序号小于16的,变量group赋值为high-wbc,否则,赋值为low-wbc*/
	else group='low-wbc';
	t=abs(lt);                        /*求变量lt的绝对值,并赋给t*/
	cards;
2 -2.5 3.5 4 4 -5 6 -6 7 -7 8 -9 10.5 12.5 19
2.5 5 7 -8.5 9 -10 11 -11 12 13 -14 15 -16 17
-18 19 -20 21 24 32
;

proc lifetest data=sc
               method=lt   /*选择LT寿命表法求生存率等指标*/
			   plots=(s,ls,lls,h);  /*输出生存函数图、风险函数图等*/
	 time t*censor(1);  /*定义生存时间和截尾指示变量,失效事件标记为0,截尾事件标记为1*/
	 strata group;      /*定义group为生存率比较的分组变量*/
run;

/*------乘积极限法-----*/
data cj;
	input t@@;
	if t<0 then censor=1;   /*t<0的生存时间代表是删失数据,给删失数据的指示变量censor赋值为1*/
	else censor=0;
	if _n_<16 then group='A';  /*给A组合B组赋组号*/
	else group='B';
	t=abs(t);         /*求生存时间绝对值*/
	cards;
28 29 175 195 309 -377 -393 -421 -447 452 -709 -744
-770 -1106 1206 34 88 137 199 280 291 -299 -300 309
351 358 369 370 375 382 392 -429 451 -1119
;
run;

proc lifetest data=cj
                method=PL      /*使用乘积极限法计算生存率*/
				plots=(s,ls,lls,h);   /*画出生存率图等等*/
	time t*censor(1);        /*定义生存时间和截尾指示变量*/
	strata group;            /*定义group为生存率比较的分组变量*/
run;

/*------Cox回归-----*/
data cox;
	input group renal day;   /*输入变量分别为:组别、是否肾功能损害、生存日数*/
	censor=(day<0);          /*根据生存日数的正负确定截尾指示变量,1代表截尾,0代表正常*/
	days=abs(day);          /*取生存日数绝对值*/
	cards;
1 1 8
1 0 52
1 1 58
1 1 63
1 1 63
1 0 220
1 0 365
1 0 452
1 0 496
1 0 -528
1 0 -560
1 0 -676
2 1 13
2 1 18
2 1 23
2 0 70
2 0 76
2 0 180
2 0 195
2 0 210
2 0 232
2 0 300
2 0 396
2 0 -490
2 0 -540
;

proc phreg data=cox;        /*使用PHREG过程来实现cox回归生存率分析*/
	model days*censor(1)=group renal;   /*cox回归模型:生存时间*截尾指示变量=组别 是否肾功能损害*/
              /* / ties=breslow        使用breslow的近似似然估计来估计生存率,默认选项,也可以选择discrete或efron*/
             /*selection=backward;  建模方法选择,这里为后向选择法*/
run;

 

猜你喜欢

转载自blog.csdn.net/Tiaaaaa/article/details/58614529
SAS