I need to convert a character variable into a numeric variable, by means of an expression in an Extract transformation.
The character variable is called Cust_No, and has the format $8. It needs to become a numeric variable with the format 8.0.
How can I accomplish this? I'm going insane experimenting with PUT, PUTC, PUTN, INPUT, INPUTN, INPUTC, etc. Whenever I think I've done it, the SQL Join tells me that I have the wrong data type.
I thought it would be correct to use this: input(Cust_No, 8.) However, that just turns all the values blank.
Thanks.
Hi,
Have you tried this:
data temp;
set your_data;
new_Cust_no = Cust_no * 1;
run;
Good luck!
Anca.
Thanks. For some reason, when I do either of those things, the variable becomes blank, as though it refuses to be numeric.
Out of curiosity, should I be able to do an inner join on character variables?
Yes, you should be able to do inner join on character variables.
Would you, please, share the code?
And a small sample data?
How about
new_var = input(old_var,best.);
Thanks.
Hi,
You are on the right path. input() will convert the character variable into numeric. it should work.
try this
x=input(Cust_No, 8.);
so are you trying that in sql, could you please send me the code you have used in sql.
Thanks,
Jagadish
Sounds like your character variable is either blank or is longer than 8 characters and is right aligned so that the first 8 positions are blank.
Resolved it using characters instead. Thanks for your advise though, I learned something.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.