BookmarkSubscribeRSS Feed
huffa9299
Fluorite | Level 6

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.

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Like this?

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

 

 

 

s_lassen
Meteorite | Level 14

You may get away with using the DBSASTYPE option:

data new;
  set dblib.mydata(dbsastype=(orig_var='CHAR(8)'));
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2415 views
  • 0 likes
  • 3 in conversation