This is a commonly asked question when learning to program so it's within the realm of 'semi-decent' questions. It teaches you how information is carried across rows, conditional logic and how to identify the end of a file. There are automated ways, but often these basics are ignored. I suspect this is the answer your professor is looking for, since it's the most basic solution I can think of, besides the PROC SORT method.
Using the test data from @novinosrin, the approach outlined below works well. It matches his answer with the IFN so that's another viable option as well.
... View more