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:
company | month | people |
A | 3 | 232 |
B | 2 | 53 |
C | 5 | 646 |
D | 9 | 244 |
E | 12 | 2609 |
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.
Like this?
proc sql;
create table WANT as
select VAR1, VAR2, put(VAR3,8.) as VAR3, VAR4
from HAVE;
run;
You may get away with using the DBSASTYPE option:
data new;
set dblib.mydata(dbsastype=(orig_var='CHAR(8)'));
run;
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!
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.