hi FredrikE, your code works perfectly fine (and much more efficient). I tried and it works. It just that I am a new user of SAS, and I don't quite understand how the code starting from ---data lu--- work. Pardon me for the naivety as proc format is a very unfamiliar procedure for me. Whereas the other method suggested by Chris, although it involves a bit more coding, I can see the logic behind it. having said that, your approach is brilliant, and I would have accepted your code as solution also if the forum rules allow. also, thank you everyone else for your contribution.
... View more