DATA Step, Macro, Functions and more

How to convert numeric variable to character without adding or dropping

Reply
Occasional Contributor
Posts: 8

How to convert numeric variable to character without adding or dropping

Hello,

 

I have a dataset that has variable that is originally a numeric in the sql server I pull it from. I want to change this variable to a character without changing the order of the variables.  I know of the put/drop/rename syntax like this:

data new;
   orig_var = 189;
   new_var = put(orig_var,8.);
   drop orig_var;
   rename new_var = orig_var;

run;

 

 

But i am trying to do this without having the variables change order, and the above syntax moves the "new_var" to the end of the dataset.

 

 

that dataset looks like this:

companymonthpeople
A3232
B253
C5646
D9244
E122609

 

my goal is to have "month" changed to a character value without having to use a RETAIN step afterwards to regain the original order of the variables.

 

Thank you for any help you could provide.

PROC Star
Posts: 2,355

Re: How to convert numeric variable to character without adding or dropping

Posted in reply to huffa9299

Like this?

proc sql;
  create table WANT as 
  select VAR1, VAR2, put(VAR3,8.) as VAR3, VAR4
  from HAVE;
run;

 

 

 

PROC Star
Posts: 265

Re: How to convert numeric variable to character without adding or dropping

Posted in reply to huffa9299

You may get away with using the DBSASTYPE option:

data new;
  set dblib.mydata(dbsastype=(orig_var='CHAR(8)'));
run;
Ask a Question
Discussion stats
  • 2 replies
  • 99 views
  • 0 likes
  • 3 in conversation