In reply to Jacob.

Jacob,

This is an interesting programming problem. You can post such questions to the forums at communities.sas.com, and I'll bet that you receive an answer fairly quickly, with a good explanation. Note that before you can post, you must create a free sas.com profile to log in.

Your question is probably best suited to the DATA step forum.

Chris