/*just works for your available data*/
data raw;
input type:8. trade_date:yymmdd10. amout_pay:8. repay_date:yymmdd10. amount_earn:8.;
format trade_date repay_date date10.;
cards;
1.2 2013-12-12 300 . .
2 . . 2013-12-23 300
;
run;
data final(keep=type day amount);
array temp{4} _temporary_;
array trade{4} trade_date amout_pay repay_date amount_earn ;
set raw end=last;
do i=1 to dim(trade);
if not missing(trade(i)) then temp(i)=trade(i);
end;
if last then do;
day=temp(3)-temp(1);
amount=temp(4)-temp(2);
output;
end;
run;