I suggest you run your code in a SAS DATA step, either using DATALINES; with an INPUT statement, or with a SET (from a previous SAS data member). Then add two statements, as shown below, around your code to generate diagnostics:
PUTLOG ">BEFORE>" / _ALL_;
* your code goes here. ;
PUTLOG ">AFTER>" / _ALL_;
With the additional DATA step processing diagnostics, I would expect you can see the processing results and reasoning with your own code. If the problem still exists, paste the entire SASLOG output into your post for the forum subscribers to respond with feedback. It's important that you share your exact DATA step code, using COPY and PASTE for accuracy and purpose.
Thanks all for your kindly response.
Sivas, that's eactly what troubles me. This piece of example is from an old program which had been runing for years. Someone found the problem with the output data recently, and I checked the process and identified the issue. It should work as you pointed out, but it didn't. Could that be possible it is caused by a SAS version problem? I have reasons to believe the code used to worked well. (Of course I can't be 100% sure.) An update SAS version in our unix environment last year may caused the problem. Again, just my guess.
As was suggested, share your "executed" SAS code with additional diagnostics in a SASLOG (pasted in your post), otherwise feedback cannot be accurately provided, based on the lack of actual SAS output.