You didn't ask a question, so I can't tell whether you are saying "here is how to do this" or whether you are asking "is this the best way to do this."
If the former, yes, this is a good way to compute cumulative sums across rows of a matrix.It is a clever algorithm.
If you are asking whether this is the fastest way, I'll offer two observations: you can use the LAG function (introduced in SAS/IML 9.22) to speed up Step2, and you don't need the REPEAT function when forming the OUTPUT matrix. Thus the following code is slightly more efficient:
start rs(x);
Step1 = cusum(x);
Step2 = lag(Step1[,ncol(Step1)], 1); /* returns missing in Step2[1] */
Step2[1] = 0; /* replace missing value with 0 */
Output = Step1 - Step2;
return( Output);
finish;
Unless your matrices are huge, it doesn't really matter which module you run. In fact, unless the number of rows is huge, you can just use a simple DO loop and the computation is just as fast:
Output = j(nrow(x), ncol(x));
do i = 1 to nrow(x);
Output[i,] = cusum(x[i,]);
end;