BookmarkSubscribeRSS Feed
EinarRoed
Pyrite | Level 9

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

6 REPLIES 6
AncaTilea
Pyrite | Level 9

Hi,

Have you tried this:

data temp;

    set your_data;

    new_Cust_no = Cust_no * 1;

run;

Good luck!

Anca.

EinarRoed
Pyrite | Level 9

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?

AncaTilea
Pyrite | Level 9

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.

Jagadishkatam
Amethyst | Level 16

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
Tom
Super User Tom
Super User

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.

EinarRoed
Pyrite | Level 9

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 6 replies
  • 1565 views
  • 4 likes
  • 4 in conversation