Hello! I have data that has 3 variables-- month, ID, and value-- for stock holdings in a portfolio. There are repeats of IDs as the stock could have been held for multiple months. I am trying to how the portfolio changed for a given month compared to the month after. I want it to compare all the IDs for a given month with all the IDs for the month afterwards (so given month + 1). Then, if there are IDs that are in one month but not the other (buying or selling of a stock), I want to record those ID numbers. Additionally, if the ID number shows up in both of the months, I want to compare the value for the ID and record that. For example, if this was my data: 1/30/2016 US1 20 1/30/2016 US2 34 2/28/2016 US1 10 2/28/2016 US3 7 I would want to know that US1 changed from 20 to 10, US2 was no longer held by 2/28/2016 and US3 was bought in 2/28/2016. I don't have a lot of SAS experience but I tried using proc compare. I don't know how to get it compare variables ONLY when the months are 1 month apart. Is there a better way to approach this? I also tried doing a while loop with a when statement but I could not figure out how to get the IDs to compare only when there is a month difference. I am using SAS 9.4. Thank you so much in advance!
... View more