/******************************************************************
* 分层 log-rank 完整示例：按 IxRS 基线风险层控制比较
* 数据: example.csv（原创模拟 ADTTE 风格数据）
* 约定: CNSR=0 事件，CNSR=1 删失
* 环境: SAS 9.4 / SAS/STAT 14.1+
******************************************************************/

proc import datafile="example.csv" out=adtte dbms=csv replace;
  guessingrows=max;
run;

data adtte_os;
  set adtte;
  where upcase(paramcd)='OS' and upcase(anl01fl)='Y';
run;

proc freq data=adtte_os;
  tables stratum1*trt01p*cnsr / missing;
run;

ods graphics on;
proc lifetest data=adtte_os plots=survival(atrisk);
  time aval*cnsr(1);
  strata stratum1 / group=trt01p order=internal;
run;
ods graphics off;

/* 读取 "Stratified Tests of Homogeneity" 中 Log-Rank 行的
   Chi-Square、DF 与 Pr > Chi-Square；该检验本身不估计 HR。 */
