I have a data with firmid(id) and returns(ret). I want for each id calculate the mean of the top 5% returns, the mean of the left 95% returns, and take the difference between them. I created a new variable rank, which indicates whether the ret is 5%, 10%, 15%, etc. and mark it as 1, 2, ...20 (20 groups). how can I use a proc sql to simply calculate this? I want to write something like proc sql; create table want as select*, (mean(ret) if rank=1) - (mean(ret) if rank>1) as diff from have group by id; quit; Please help me with this.
... View more