This is where using the POINT= option of the SET statement helps:
data a_k resid;
set akkk;
output a_k;
if mad_command ne 0 then do;
output resid;
p=_n_-1;
set akkk point=p;
output resid;
end;
run;
This program outputs every akkk record to dataset a_k. If outputs the selected record, and its predecessor to resid. Note the original preceding record now follows the precipitating record. If instead you want to preserve the original order, you can:
data a_k resid;
set akkk;
output a_k;
if mad_command ne 0 then do p=_n_-1 to _n_;
set akkk point=p;
output resid;
end;
run;