Its quite hard to see what your after from that, test data in the form of a datastep and what you want out will help. Can you not sort the data, then use lag()? SQL can simply merge these too. If its an agregate then a where might be better.
Catch up on SAS Innovate 2026
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.