BookmarkSubscribeRSS Feed
sassharp
Calcite | Level 5

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.

2 REPLIES 2
Linlin
Lapis Lazuli | Level 10

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;

Bayes
Calcite | Level 5

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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 804 views
  • 0 likes
  • 3 in conversation