varables a e f h z t x1 x2 x3 x4 x5 w in a given data set 'have'
here a,e,f,h,z,t,x1,x2,x3,x4,x5,w are variables.
Here x1 x2 x3 x4 x5 are numeric.
I can change numeric to character
data want;
set have;
z1=put(x1,5.);
z2=put(x2,5.);
z3=put(x3,5.);
z4=put(x4,5.);
z5=put(x5,5.);
drop x1 x2 x3 x4 x5 ;
rename z1=x1;
rename z2=x2;
rename z3=x3;
rename z4=x4;
rename z5=x5;
run;
Problem?
want data set variables are in this order
a e f h z t w x1 x2 x3 x4 x5
Need?
but do need in original order
a e f h z t x1 x2 x3 x4 x5 w
please dont say use retain before set statement. There are 500+ variables in the original data set.
is there any way? with out writing each variable name in retain statement?
thanks.
try the code below:
proc contents data=old out=temp(keep=name varnum);
proc sort data=temp; by varnum;run;
proc sql noprint;
select name into :order separated by ' '
from temp;
quit;
data new;
retain ℴ
set old;
...;
run;
Change the variable order method(a Dummy Format application).
original order: a e f h z t x1 x2 x3 x4 x5 w
new order: a e f h z t w x1 x2 x3 x4 x5
data want;
format a e f h z t w x1 x2 x3 x4 x5;
set have;
run;
* or ;
data want;
format a e f h z t w;
set have;
run;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.