You might want to include a description of what you mean -- I'm guessing it's this classic problem, sometimes assigned as a programming learning exercise.
If it is an assignment....do you have examples of what you've tried? There are probably elegant solutions in SAS/IML, but I think a DATA step approach could work as well.
Ready to join fellow brilliant minds for the SAS Hackathon?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.