%macro movevars(dsetin,dsetout,varlist=,moveto=end); %*--utility macro will examine variables in dataset ***&dsetin*** (default value is _last_) and create a new dataset pointed to by ***&dsetout*** (which can be the same as desetin and defaults to null). ***&varlist*** is the NAME of a macro variable containing a list of variables found on dsetin -- must be specified, no default. These variables will be moved to either be the first variables on the output dataset or the last (rightmost). The vale of ***&moveto*** can be start or left, end or right. start or left means move these variables so they become the first of leftmost on the dataset. end or right means they get moved to the other end of the dataset. Defaults to end. --*; %if %nrbquote(&dsetin)=&null %then %let dsetin=_last_; %if %nrbquote(&varlist)=&null %then %do; %put *****ERROR: required parm varilist was not specified ***; %goto endmac; %end; data _inlist(keep=&&&varlist ) _notinlist(drop=&&&varlist) ; if 0 then set &dsetin; run; data &dsetout; set %if &moveto=end or &moveto=right %then %do; _notlinlist _inlist %end; %else %do; %*--the references are to two empty datasets but they cause the PDV to get defined. --; _inlist _notinlist %end; &dsetin; run; %endmac: %mend movevars;