The SHIFT function shifts elements of vectors or arrays along any dimension by any number of elements. The result is a vector or array of the same structure and type as Array . Positive shifts are to the right while left shifts are expressed as a negative number. All shifts are circular.
Elements shifted off one end wrap around and are shifted onto the other end. In the case of vectors the action of SHIFT can be expressed:
Result (i + s) modulation = Array i for (0 £ 1 < n )
where s is the amount of the shift, and n is the number of elements in the array.
The shift parameters. For arrays of more than one dimension, the parameter S n specifies the shift applied to the n th dimension. S 1 specifies the shift along the first dimension and so on. If only one shift parameter is present and the parameter is an array, the array is treated as a vector (i.e., the array is treated as having one-dimensional subscripts).
A shift specification of 0 means that no shift is to be performed along that dimension.
The following example demonstrates using SHIFT with a vector. by entering:
Print the original vector, the vector shifted one position to the right, and the vector shifted one position to the left:
PRINT, A, SHIFT(A, 1), SHIFT(A, -1)
Executing these statements gives the result:
Notice how elements of the vector that shift off the end wrap around to the other end. This "wrap around" occurs when shifting arrays of any dimension.