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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.