Thanks for your input.
However I have SAS 4.3 in where hash tables with duplicate keys cannot be used.
Thanks& regards,
Shivangi
So I suppose you have EG 4.3, and your BASE SAS version is 9.1. Anyway, the "multidata: 'y'" option is to put there for the sake of robustness. Given the nature of your data, it is highly unlikely that you will have duplicated keys "h.definekey('_stock','_Buy_Sell','_TRANS_DATE');", therefore you should be fine if you remove this option. However, there maybe other methods (such setcur()) that are not supported by 9.1, so Hash() is still may not good for your settings.
Haikuo
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
Tammy,
Repost your question as a new question. More people are likely to respond to a new question than they would respond to one that is 2 years old and already marked as having been answered.
Will do. Thank you.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.