In reply to Mark.

If you want the solution in Base SAS, post your question to the Base SAS Programming support community. If you want a SAS/IML solution, post to the SAS/IML Support Community. Provide sample data and the output that you expect/