@DaveStar:
Yes, you can use both two 1-dimensional arrays and one 2-dimensional array for the purpose.
However, in the latter case you'd need to add a dummy variable because the number of variables in every row and column must be identical. It stands to reason, as a 2-dim array is a rectangular matrix, and you cannot have it with a corner cell simply absent. Compare the second and third steps below:
data tb1 ;
array xxx [12] x0-x11 (0 1 . 2 3 4 5 . 6 0 8 7) ;
run ;
data tbl2 ;
set tb1 ;
array xxx [12] x0-x11 ;
array www [11] w1-w11 ;
do i = 1 to dim (xxx) - 1 ;
www[i]= divide (xxx[i+1] - xxx[i], xxx[i]) ;
end ;
run ;
data tbl2 (drop = _:) ;
set tb1 ;
array xw [2, 12] x0-x11 w1-w11 _wdummy ;
do i = 1 to dim (xw, 2) - 1 ;
xw[2,i]= divide (xw[1,i+1] - xw[1,i], xw[1,i]) ;
end ;
run ;
Heed also what @ballardw has said. First, compared to simple square brackets, curly braces are pain both to type and look at. Personally, I always use square brackets both in array definitions and references. Second, the DIVIDE function is much preferable to the division operator in terms of auto-handling division by zero and by null. (If you run the above code, you'll see some "missing values generated" notes in the log but they result from the minus (-) operator.)
Kind regards
Paul D.
... View more