SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Converting a character variable into a numeric variable

Reply
Frequent Contributor
Posts: 90

Converting a character variable into a numeric variable

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. Smiley Happy

Super Contributor
Posts: 543

Re: Converting a character variable into a numeric variable

Posted in reply to EinarRoed

Hi,

Have you tried this:

data temp;

    set your_data;

    new_Cust_no = Cust_no * 1;

run;

Good luck!

Anca.

Frequent Contributor
Posts: 90

Re: Converting a character variable into a numeric variable

Posted in reply to AncaTilea

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?

Super Contributor
Posts: 543

Re: Converting a character variable into a numeric variable

Posted in reply to EinarRoed

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.

Trusted Advisor
Posts: 1,137

Re: Converting a character variable into a numeric variable

Posted in reply to EinarRoed

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

Thanks,
Jag
Super User
Super User
Posts: 7,083

Re: Converting a character variable into a numeric variable

Posted in reply to EinarRoed

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.

Frequent Contributor
Posts: 90

Re: Converting a character variable into a numeric variable

Resolved it using characters instead. Thanks for your advise though, I learned something. Smiley Happy

Ask a Question
Discussion stats
  • 6 replies
  • 403 views
  • 4 likes
  • 4 in conversation