Programming statements are used to create or modify the values of the explanatory variables in the MODEL statement. They are especially useful in fitting models with time-dependent explanatory variables. Programming statements can also be used to create explanatory variables that are not time dependent. For example, you can create indicator variables from a categorical variable and incorporate them into the model. PROC PHREG programming statements cannot be used to create or modify the values of the response variable, the censoring variable, the frequency variable, or the strata variables.
ARRAY arrayname <[ dimensions ]> <$> <variables-and-constants>;
CALL name <(expression <, expression …>)>;
DO <variable = expression <TO expression> <BY expression>> <, expression <TO expression> <BY expression>> …
<WHILE expression> <UNTIL expression>;
IF expression THEN program-statement;
variable = expression;
variable + expression;
PUT <variable> <=> …;
SUBSTR(variable, index, length)= expression;
By default, the PUT statement in PROC PHREG writes results to the Output window instead of the Log window. If you want the results of the PUT statements to go to the Log window, add the following statement before the PUT statements:
DATA step functions are also available. Use these programming statements the same way you use them in the DATA step. For detailed information, see SAS Statements: Reference.
Consider the following example of using programming statements in PROC PHREG. Suppose blood pressure is measured at multiple times during the course of a study investigating the effect of blood pressure on some survival time. By treating the blood pressure as a time-dependent explanatory variable, you are able to use the value of the most recent blood pressure at each specific point of time in the modeling process rather than using the initial blood pressure or the final blood pressure. The values of the following variables are recorded for each patient, if they are available. Otherwise, the variables contain missing values.
censoring indicator (with 0 as the censoring value)
blood pressure on entry to the study
blood pressure at
blood pressure at
proc phreg; model Time*Censor(0)=BP; BP = BP0; if Time>=T1 and T1^=. then BP=BP1; if Time>=T2 and T2^=. then BP=BP2; run;