array ʃarray_typeʅ array_name(dimension1ʃ, ..., dimensionNʅ) ʃsaveʅ;
The
array statement creates an
array with the name
array_name. Only one array at a time can be declared with the array statement. The array name must be unique and must contain only letters, numbers, or the underscore character. The name must begin with a letter. You can declare arrays in
PROC GLOBAL or locally in functions or procedures.
Arrays can be numeric, alphanumeric or string. By default an array is numeric, but the type can be modified by specifying the array_type. If creating an alphanumeric array, the length of each array element can be specified by definining the array_type as follows:
If array_length is not specified, each element will be 16 characters.
The size of each dimension is specified by supplying a constant positive numeric value,
dimension1 to
dimensionN. An array must have at least one dimension. CSPro supports arrays of an unlimited number of dimensions. A previously defined numeric value can also be used to specify the dimension size. The
array.length function can be used to query the size of a dimension.
The initial values of the elements of an array can be set when declaring the array by listing each value, separated by a comma. If some values are defined and then followed by ..., that set of values will be used over and over until the entire array has been initialized.
With a numeric array, each element starts with the value 0. For alphanumeric and string arrays, each element starts as a blank string. If using a numeric
saved array, the initial array contents are
default.
The optional keyword
save indicates that the array values should be saved to a file and loaded from that file when the program is run again. This allows you to maintain the values of the arrays across multiple runs of the same program. When one or more arrays in the program are marked with
save, the first time the application is run, a
saved array file is created and the values of the arrays are written to the file at the end of program execution. On consecutive runs of the program, the initial values of the arrays are read in from the file. This is particularly useful for setting the initial values of hot decks. In this scenario, the program is run twice. The first run fills the hot deck and saves the hot deck array to the file. The second run loads the values saved from the first run and uses them as the initial values for the hot deck for imputation. See
Initialize Hot Decks in Program Logic for more information.
All arrays marked with save in the application are written to the same file. By default this file has the same name as the application but with a .sva file extension appended to it (for example, MyApplication.bch.sva). You can modify the name of the saved array file by using the PFF SaveArray attribute.
PROC GLOBAL
array string Months(12) = "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec";
function string FormatDate()
FormatDate = maketext("%d %s %d", sysdate("DD"), Months(sysdate("MM")), sysdate("YYYY"));
end;