In reply to D Gibson.

The comments of a blog post are not ideal for posting code, so post sample data and the program you've written so far to the SAS/IML Support Community. Someone will be able to help you figure out how to complete the program.