I wanted to calculate holding period of mutual fund, If the quantity is sold in any month then the program should automatically create a new column called Holding period and then calculate the difference of duration as shown in below table.
For example for mutual fund no :124, The current month quantity is 3000 and previous month was 4000 that means its sold in this month by 1000 unit.
But if the quantity is never sold like for mutual fund no :236 then it should give the duration from current month till first month.
Mutual Fund | Quantity_201904 | Quantity_201903 | Quantity_201902 | Quantity_201901 | Holding Period_1 | Holding Period_2 |
124 | 3000 | 4000 | 1500 | 2000 | 1 | 2 |
236 | 4000 | 3000 | 2500 | 500 | 3 | 0 |
456 | 7000 | 4000 | 3500 | 800 | 3 | 0 |
What if there are choices to be made? For example:
January: 1000
February: 2000
March: 3000
April: 2000
The 1000 that were sold in April could come from any of the previous three months that were all purchases. What should the holding period be?
What if the pattern looks like this:
January: 1000
February: 3000
March: 5000
April: 3500
May: 2000
What's the holding period for May, when the 1500 that were sold were purchased during more than one month?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.