- data stock;
- input ID Monthyear return;
- cards;
- 101 1000 0.05
- 101 1001 0.06
- 101 1002 0.04
- 101 1003 0.08
- 101 1004 0.02
- 102 1001 0.12
- 102 1002 0.07
- 102 1003 0.03
- 103 1001 0.04
- 103 1003 0.08
- 103 1004 0.02
- ;
- proc sql;
- create table temp as
- select a.*
- from stock as a /*as可要可不要*/
- left join stock as b
- on a.id=b.id
- and a.monthyear-1<=b.monthyear<=a.monthyear;
- quit;
- proc sql;
- create table temp1 as
- select
- id,
- monthyear,
- return,
- count(return) as count
- from temp
- group by id,monthyear,return;
- quit;