Well, this is certainly a difficult one, and I suspect there is an easier way, but this will work. (I tried several ways to do this without a macro but could not find a solution.)
Code:data test; input X Y Z; datalines; 1 2 . . 3 . . 4 . . 5 . . 6 . run; %macro test(data_in=,data_out=); proc sql noprint; select monotonic() into:row_nums separated by ' ' from test; quit; proc sql noprint; select max(monotonic()) into:column_length from test; quit; data &data_out.; set &data_in.; %let k=1; %let row_op = %scan(&row_nums., &k.); %do %while(&k. < &column_length.); z=x+y; newz=lag1(z); if _n_ <= &row_op. then x=x; else x=newz; %let k=%eval(&k.+1); %let row_op = %scan(&row_nums., &k.); %end; z=x+y; drop newz; run; %mend test; %test(data_in=test,data_out=test2);




Reply With Quote

