Hi, tsmk is my time-dependent covariate, deathstatus_inhance is censor, and stime_inhance is time. The "Change step" worked well, but the "Count step" only worked for four observations and stopped. Please help me to correct my code. DATA analysis.change;
SET analysis.smk_stime2;
ARRAY tsmk_(*) tsmk_1-tsmk_5; *call in the time-varying smoking variables;
ARRAY chng(5); *the new indicator variables;
t=1; *initialize the position variable for the indicator variables;
DO i = 2 TO 5;
IF tsmk_(i) NE tsmk_(i-1) THEN DO; *detects whether there is a change in smoking status;
chng(t) = i-1; *assigns the last year the status remained constant;
t=t+1;
END;
END;
RUN;
DATA analysis.count;
SET analysis.change;
ARRAY tsmk_(*) tsmk_1-tsmk_5; /* call in the time-varying smoking variables */
ARRAY chng(*) chng1-chng5; /* call in the indicator variables */
start = 0; /* initialize the beginning time for the study */
censor2 = 0; /* initialize the new censor variable */
t = 1; /* initialize the position variable for the indicator variables (chng1-chng5) */
DO i=1 TO stime_inhance; /* makes sure we only output the records that smoking status remains constant */
IF (chng(t) > . and chng(t) < stime_inhance) or i = stime_inhance THEN do;
/* assign the value of smoking status */
IF chng(t) > . THEN smoking_status = tsmk_(chng(t));
ELSE smoking_status = tsmk_(stime_inhance); /* assign the end time */
stop = min(chng(t), stime_inhance); /* assign the value of the censor variable */
IF i = stime_inhance THEN censor2 = deathstatus_inhance; /* assign the new start time */
IF t > 1 THEN start = chng(t-1); /* move the position variable */
t = t + 1;
OUTPUT; /* output the record to the new dataset */
end;
END;
RUN;
... View more