When outcomes occur in clinical trials before treatment can be given, neither intent-to-treat nor according-to-protocol analyses give optimal estimates of the treatment effect. A better approach employs a time-dependent variable for treatment. Intent-to-treat analyses are conservative, biasing against treatment; according-to-protocol analyses bias in favor of treatment. We show how to measure the effect of a time-dependent variable in a logistic regression using person-time intervals as units of measurement and describe appropriate methods for reporting model performance. The method is applied to develop a model to predict the probability that a patient with a myocardial infarction will have a sudden cardiac arrest within 48 hours of presentation to emergency medical services both when treated with thrombolysis and when not treated. We use a time-dependent treatment variable because many patients went into cardiac arrest while awaiting treatment. This technique has been programmed into an electrocardiograph for real-time use in an emergency department.