Why presume SAS compiler is interrogating the SAS program source statements top-down and left to right within your DATA step? Also, don't presume that SAS actually stores the variables in any particular manner (such as the CONTENTS report order list), given that there are features like COMPRESS which could influence the SAS system's behavior (just to start).
True, I am presuming that the SAS compiler is interrogating the SAS program source statements top-down and left to right. All source material I have seen to date, relating to SAS compilation, explains it that way.
Also true, I like to presume that SAS actually does store the variables in a particular manner. Case in point would be the use of the RETAIN to 'reorder' variables in a particular way in a data step, because we know what effect the RETAIN statement placed before a SET has.
What is clear here is that my understanding of the compilation phase is not complete enough to explain what is causing this unexpected (for me anyway) effect.
Again, your use of the RETAIN may or may not have any influence on SAS internal behavior for ordering its observations and variables. I know that since SAS v6 when SAS was re-written to separate the various system-interface layers, there was significant optimization efforts achieved for various supported OS platforms. So, you may think that you are influencing SAS variable order, but I'd humbly submit that SAS has its own internal "smarts" doing what it needs for optimization depending on the OS environment and possibly other OPTIONS / CONFIG settings you may have declared (or defaulted to). FYI - have had enough energy from my part on this topic. Later.