The index creation operator (:) creates a row vector with a first element that is value1. The second element is value1+1, and so on, until the last element which is less than or equal to value2.
For example, the following statement creates the vector s
which contains consecutive integers, shown in Figure 24.13:
s = 7:10; print s;
If value1 is greater than value2, a reverse-order index is created. For example, the following statement creates the vector r
which contains a decreasing sequence of integers, shown in Figure 24.14:
r = 10:6; print r;
Neither value1 nor value2 is required to be an integer. Use the DO function if you want an increment other than 1 or .
The index creation operator also works on character arguments with a numeric suffix. For example, the following statements create a sequence of values that begin with the prefix "var", shown in Figure 24.15:
varList = "var1":"var5"; print varList;
Sequences of character values are often used to assign names to variables. You can use the string concatenation operator to dynamically determine the length of a sequence, as shown in the following statements:
x = {1 2 3 4, 5 6 7 8, 7 6 5 4}; numVar = ncol(x); /* 4 columns */ varNames = "X1":"X"+strip(char(numVar)); /* "X1":"X4" */ print x[colname=varNames];
Lastly, you can use the index operator to create a sequence of English letters, in either increasing or descending order, as follows:
a = "a":"h"; b = "P":"L"; print a, b;