The BEGINCNST and ENDCNST statements define a block within which PROC MCMC processes the programming statements only during the setup stage of the simulation. You can use the BEGINCNST and ENDCNST statements to define constants or import data set variables into arrays. Storing data in arrays enables you to work with data that are not identically distributed (see the section Modeling Joint Likelihood) or to implement your own Markov chain sampler (see the section UDS Statement). You can also use the BEGINCNST and ENDCNST statements to assign initial values to the parameters (see the section Assignments of Parameters).
Whenever you have programming statements that calculate constants that do not need to be evaluated multiple times throughout the simulation, you should put them within the BEGINCNST and ENDCNST statements. Using these statements can reduce redundant processing. For example, you can assign a constant to a symbol or fill in an array with numbers:
array cnst[17]; begincnst; offset = 17; do i = 1 to 17; cnst[i] = i * i; end; endcnst;
During the setup process, PROC MCMC evaluates the programming statements within the BEGINCNST/ENDCNST once for each observation in the data set and ignores the statements in the rest of the simulation.
Sometimes you might need to store variables, either from the current input data set or from a different data set, in arrays and use these arrays to specify your model. The READ_ARRAY function is convenient for that purpose.
The following two forms of the READ_ARRAY function are available:
where
rc returns 0 if the function is able to successfully read the data set.
data-set specifies the name of the data set from which the array data is read. The value specified for data-set must be a character literal or a variable that contains the member name (libname.memname
) of the data set to be read from.
array specifies the PROC MCMC array variable into which the data is read. The value specified for array must be a local temporary array variable because the function might need to grow or shrink its size to accommodate the size of the data set.
col-name specifies optional names for the specific columns of the data set that are read. If specified, col-name must be a literal string enclosed in quotation marks. In addition, col-name cannot be a PROC MCMC variable. If column names are not specified, PROC MCMC reads all of the columns in the data set.
When SAS translates between an array and a data set, the array is indexed as [row,column].
The READ_ARRAY function attempts to dynamically resize the array to match the dimensions of the input data set. Therefore, the array must be dynamic; that is, the array must be declared with the /NOSYMBOLS option.
For examples that use the READ_ARRAY function, see Modeling Joint Likelihood, Time Independent Cox Model, and Implement a New Sampling Algorithm.