I am trying to create a 3 x13 matrix called it deaths, that contains the sum of the number of deaths for each of three years. The matrix called outcome is a column vector with each row containing 1 to 3 years of observations for each person. Let's say there are 1,000 rows. The matrix called time also has 1,000 rows, but in addition, each of 3 columns contains an indicator for whether the record is from time 1 (col 1), time 2 (col 2) and time 3 (col 3). I want to sum the deaths in outcome for each individual year. That is, I want to use the indicator in the time matrix to sum those specific rows in the outcome matrix. Example: Outcome is first column below. time (col1) time (col 2) time (col3) are the columns of the time matrix... row 1 0 1 0 0 row 2 0 0 1 0 row 3 0 0 0 1 row4 0 1 0 0 row 5 1 0 1 0. So the matrix that I want called deaths would sum row 1 and 4, row 2 and 5, to reflect the one and two years totala, I use the following code that does not work: deaths=j(3,1,0); do yr=1 to 3; deaths[yr]=sum(outcome[time[yr]=1,])); end; run; Does anyone have a suggestion basically for using a matrix to select specific rows from another matrix. Thanks
... View more