Suppose you have two datasets with same named variables. You want the order of the variables to be same in both the datasets.
Let's create two datasets
data abc;SAS Code : Reordering Variables
input a b c;
cards;
1 3 4
2 4 5
;
run;
data bac;
input b a c;
cards;
1 3 4
2 4 5
;
run;
proc sql noprint;Note : Put library and dataset name in LIBNAME and MEMNAME (in caps) in the above code. RETAIN is used to reorder variables in a SAS dataset.
select name
into :reorder
separated by ' '
from dictionary.columns
where libname="WORK" and
memname="ABC"
order by name;
quit;
data bac;
retain &reorder.;
set bac;
run;
Hi Deepanshu ,
ReplyDeleteWill you please expalain above code a bit.
it is quite simple. Basically accessing metadata within dictionary.columns table where variable information is stored. He is storing the variable names in a macro variable called 'reorder' ordered by name variable separated by spaces. This macro variable will then have value something like 'a b c'. This is used in the retain statement in the final data step where dataset bac is created again from same bac dataset.
Deleteyes what is mean by dictionary.columns over here
ReplyDeleteIt's metadata repository where column level information is stored.
DeleteEg memname,libname,varname..
Try to use ity ou will understand.