data b;set a;by NPERMNO date type date1;
retain car1;if first.type then car1=ri;else car1=car1*ri;
retain car1_MV;if first.type then car1_MV=rmv;else car1_MV=car1_MV*rmv;
retain car1_ME;if first.type then car1_ME=rme;else car1_ME=car1_ME*rme;
if last.type then output;run;/*