My 2. Ok. First, if you have to order your fields in a specific way, I would think you would have some kind of ordering in mind which could translate into a 'codable' ORDER BY statement. Is there something with the fields that can easily identify this ordering? For instance - alphabetically arranged, or reverse alphabetic order or some such thing? If there is no such 'codable' logical order this can translate to, and you want certain fields in certain positions, then you would have to type it out. Or automate it with a convoluted macro. And here is my attempt at it(:::::::::::::::::NOT TESTED:::::::::::::::::::, just an approach) - proc contents data=have out=interim(keep = name varnum); run; <Add proc sort by name here if you want everything else arranged in alphabetic order/default collating sequence> %macro rearrange(var, after); <- var is the name of the variable you want to shift and after is the name of the variable after which shift must occur. data _null_; set interim(where=(name in ("&after" "&var"))); if upcase(name) eq upcase("&after") then call symput('var1',_N_); else call symput('var2',_N_); data list1 list2; if _N_=1 then do; length name $20 varnum 8; declare hash h(dataset:'interim', ordered: 'yes'); declare hiter hi('h'); h.defineKey('_N_'); h.definedata('name','varnum'); h.defineDone(); end; rc = hi.first(); do while (rc = 0); if _N_ LE &Var1 then output list1; else if _N_ GT &Var1 and _N_ NE &var2 then output list2; rc = hi.next(); end; run; proc sql ; select name into :list1 separated by ' ' from list1 ; select name into :list2 separated by ' ' from list2 ; quit; data want; retain &list1 &var &list2 <--- if using varnum and not name of the variable, then add additional step to derive name fo the variable ; set have; run; %mend rearrange; %rearrange(<variable to be shifted>,<variable after which shift must occur>) Call macro rearrange as many times as you want. Also, this helped - http://support.sas.com/kb/8/395.html Criticism most welcome.
... View more