This SAS event should be moved into a sub-function which is called here and the various places above. 

When you do this I would have the function take an explicit "instance ID" parameter which is always set to 0 (as this makes it easier to migrate to using instance IDs in the future).