%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 or leftmost on the dataset. end or right means they get moved to the other end of the dataset. Defaults to end. --*; %local null; %let null=; %if %superq(dsetin)=&null %then %let dsetin=_last_; %if %superq(varlist)=&null %then %do; %put *****ERROR: required parm varilist was not specified ***; %goto endmac; %end; %let moveto=%lowcase(&moveto); %if (&moveto=end or &moveto=right) %then %let _dropKeep=Drop; %else %let _dropkeep=Keep; data _firstvars(&_dropkeep=&&&varlist ) ; if 0 then set &dsetin; stop; run; data &dsetout; set _firstvars &dsetin; run; %endmac: %mend movevars;