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:
DATA _NULL_;
SET ;
PUTLOG ">BEFORE>" / _ALL_;
* your code goes here. ;
PUTLOG ">AFTER>" / _ALL_;
RUN;
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.
Scott Barry
SBBWorks, Inc.