Hello, I am very new to SAS and have a research project which requires return calculation. This discussion matches my question. However, my data allows short sale. So SHRS in your data may be negative. I need to calculate RETURN at each point of time by following First In First Out (FIFO) rule. FIFO means where the oldest entry is processed first. This is exactly the rule your are using. Original data: Date Buy/Sell Price ShrsHeld 1 Buy 10 2 2 Buy 20 5 3 Sell 30 4 4 Sell 40 -2 5 Sell 50 -4 6 Buy 60 -1 Desired ouput: Date Buy/Sell Price ShrsHeld Return 1 Buy 10 2 2 Buy 20 5 3 Sell 30 4 20 4 Sell 40 -2 90 5 Sell 50 -4 6 Buy 60 -1 -50 For example: At time 3, return is 1*(30-10)=20. At time 4, return is 1*(40-10)+3*(40-20)=90. At time 6, return is -2*(60-40)-1*(60-50)=-50. I have trouble to code it. Please help!! Thank you for your kind assistance. Best, Tammy
... View more