Help using Base SAS procedures

numeric to character conversion?????

Reply
Frequent Contributor
Posts: 110

numeric to character conversion?????

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.

Super Contributor
Posts: 1,636

Re: numeric to character conversion?????

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 Smiley Surprisedrder separated by ' '

   from temp;

quit;

data new;

  retain ℴ

  set old;

   ...;

run;

New Contributor
Posts: 2

Re: numeric to character conversion?????

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;

Ask a Question
Discussion stats
  • 2 replies
  • 178 views
  • 0 likes
  • 3 in conversation