DATA tmp;
input ID startmonth price;
cards;
1 198011 12
1 198012 13
1 198101 20
1 198102 25
1 198103 10
1 198104 40
2 201012 3
2 201101 20
2 201102 30
2 201103 5
2 201104 8
;
run;
proc sort data=tmp;
by ID startmonth;
run;
/**assume data is sorted**/
data tmp2;
do i=0 by 1 until(last.id);
set tmp;
by id ;
output;
if first.id then max=price;
if max<price then max=price;
if first.id then drawback=price/max;
if price/max<drawback then drawback=price/max;
end;
run;
proc print;run;
我是希望Max和Drawback能够上移一行,我的计算逻辑也是如果第一行,那么直接给max和drawback赋值了,怎么会下移一行,并且第一行出现缺失值呢?怎么解决?谢谢!