Shared Concepts

CODE Statement

  • CODE <options>;

This section applies to the following procedures: GENSELECT, KCLUS, LOGSELECT, PCA, PHSELECT, QTRSELECT, REGSELECT, TREESPLIT, and VARIMPUTE.

The CODE statement writes SAS DATA step code for computing predicted values of the fitted model to a file. For survival procedures, the predicted values include survival probabilities and cumulative hazards at specific time points. To score new data, you can then include the file in a DATA step.

Table 3 summarizes the options that you can specify in the CODE statement.

Table 3: CODE Statement Options

Option Description
COMMENT Adds comments to the generated code
CUMHAZ Generates cumulative hazard values at specified time points
FILE= Names the file in which to save the generated code
FORMATWIDTH= Specifies the numeric format width for the regression coefficients
INDENTSIZE= Specifies the number of spaces to indent the generated code
IPROB Computes individual predicted probabilities for ordinal response models
LABELID= Specifies a number used to construct names and labels
LINESIZE= Specifies the line size for the generated code
NOSURVIVAL Suppresses the generation of survival probabilities
NOTRIM Compares formatted values, including blank padding
PCATALL Generates probabilities for all levels of categorical response variables
SHOWTIME Creates variables that contain the time points at which predictions are made
TIMEPOINT= Specifies the time points at which survival probabilities or cumulative hazards are predicted


If you do not specify the FILE= option and if your SAS client has a default path, then the SAS scoring code is written to an external file named _code_. You can specify the following options in the CODE statement.

COMMENT

adds comments to the generated code.

CUMHAZ

generates SAS code to predict the cumulative hazard function at the time points that you specify in the TIMEPOINT= option. This option applies to the PHSELECT procedure.

FILE=filename

names the external file that saves the generated code. When enclosed in a quoted string (for example, FILE="c:mydirscorecode.sas"), this option specifies the path and filename for writing the code to an external file. If you do not specify a path but your SAS client has a default path, then the code is written to an external file named filename at that location. You can also specify an unquoted filename of no more than eight characters. If the filename is assigned as a fileref in a Base SAS FILENAME statement, the file that is specified in the FILENAME statement is opened; otherwise, if your SAS client has a default path, an external file named filename is created.

FORMATWIDTH=width

specifies the width to use in formatting derived numbers such as parameter estimates. You can specify a value in the range 12 to 32; the default is 20.

INDENTSIZE=n

specifies the number of spaces to indent the generated code. You can specify a value in the range 0 to 10; the default is 3.

IPROB

computes the individual predicted probabilities for ordinal response models. This option applies to the following procedures: GENSELECT and LOGSELECT. For a response variable Y with three levels, 1, 2, and 3, the individual probabilities are , , and .

LABELID=value

specifies a number used to construct array names and statement labels in the generated code. You can specify a value in the range 0 to 1024; the default is randomly chosen.

LINESIZE=value
LS=value

specifies the line size for the generated code. You can specify a value in the range 64 to 254; the default is 120.

NOSURVIVAL

suppresses SAS code for survival probabilities prediction. This option applies to the PHSELECT procedure. If you do not specify this option, survival procedures generate SAS code to predict survival probabilities at the time points that you specify in the TIMEPOINT= option.

NOTRIM

bases comparisons of formatted values on the full format width, including blank padding. By default, blanks at the beginning and end of strings are ignored.

PCATALL

generates probabilities for all levels of categorical response variables. This option applies to the following procedures: GENSELECT and LOGSELECT.

SHOWTIME

creates variables that contain the time points at which predictions are made. This option applies to the PHSELECT procedure. If T is the name of the failure time variable, these time point variables are named T_1, T_2, and so on.

TIMEPOINT=list | QUANTILE(probability-list)
TIME=list | QUANTILE(probability-list)

specifies the time points at which survival probabilities or cumulative hazards are predicted. This option applies to the PHSELECT procedure. You can specify a list of numbers that represent exact time points. For example:

code cumhaz timepoint = 40 to 60 by 10;

If T is the name of the failure time variable, the preceding specification requests the predicted cumulative hazard and survival probability at the time points T=40, T=50, and T=60. If you also specify the SHOWTIME option, these time points are saved in the variables T_1, T_2, and T_3, respectively. The predicted variables are named and labeled as shown in Table 4.

Table 4: Predicted Variables

T Name Label
40 C_T_1 Cumulative Hazard at T_1
50 C_T_2 Cumulative Hazard at T_2
60 C_T_3 Cumulative Hazard at T_3
40 S_T_1 Survival Probability at T_1
50 S_T_2 Survival Probability at T_2
60 S_T_3 Survival Probability at T_3


Alternatively, you can use the keyword QUANTILE to specify a list of quantile probabilities. For example:

 code timepoint = quantile(.2, .5, .8);

Survival procedures compute the 20th, 50th, and 80th percentiles from the Kaplan-Meier curve (or the Breslow curve if you also specify the ENTRY= option in the MODEL statement) and use them as the time points for the prediction.

By default, TIMEPOINT=QUANTILE(0.25, 0.50, 0.75).

Last updated: May 14, 2026