Perform a circular shift of the contents of a variable in either
an up or down direction.
It is sometimes convenient to move the elements of a
variable either up or down. Given a vector of n elements,
one question is how to handle the elements when the index
is less than 1 or greater than n. For the circular shift,
elements greater than n go to the beginning of the vector
and elements less than 1 go to the end of the vector.
For example, to circular shift the contents of the variable Y
that contains 5 elements up (or right) by one element into the
output vector Y2, we mean
Y(1) => Y2(2)
Y(2) => Y2(3)
Y(3) => Y2(4)
Y(4) => Y2(5)
Y(5) => Y2(1)
To shift the contents of Y down (or left) by one element,
Y(1) => Y2(5)
Y(2) => Y2(1)
Y(3) => Y2(2)
Y(4) => Y2(3)
Y(5) => Y2(4)
The SHIFT command is similar to the CIRCULAR SHIFT, but it handles
the end points differently.
LET <y> = CIRCULAR SHIFT <x> <nshift>
where <x> is a response variable;
<nshift> is a number or parameter that specifies how
how many elements to shift;
and <y> is a variable that contains
the shifted values.
The sign of NSHIFT specifies the direction. If NSHIFT is
negative, the shift is down (or left) and if NSHIFT is positive
the shift is up (or right). If NSHIFT is zero, then Y = X.
LET Y = CIRCULAR SHIFT X NSHIFT
= Perform a shift of a variable.
= Save data from a variable to specified rows of another
variable based on an index variable.
= Generate a patterned sequence of values.
= Sort a column of numbers.
= Rank a column of numbers.
= Code a column of numbers.
= Specifies a subset to be included in a plot, analysis,
or LET command.
= Retain specified rows or a subset of a variable.
let y = normal random numbers for i = 1 1 10
let nshift = 3
let y2 = circular shift y nshift
let nshift = -3
let y3 = circular shift y nshift
set write decimals 3
print y y2 y3
The following output is generated:
Date created: 6/19/2009
Last updated: 6/19/2009
Please email comments on this WWW page to