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.
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.