char to num

Reply
Super Contributor
Super Contributor
Posts: 328

char to num

Hello friends,


i need small help to convert character var to num.


here is the character var "A" from table "test" that i am trying to convert it into num...

table "test"

A

------------

FA09

AA20

1234

3456

8067

7687

AS34

/*if i use below code,*/

data _char_to_num;

set test;

new_a=input(a,4.);

drop a;

rename new_a=a;

run;

/*i am getting missing value as "." for couple of values*/

result table "char_to_num"

A

----------

.

.

1234

3456

8067

7687

.

/*how can i overcome this issue - please advise*/

Thanks!


Super User
Posts: 10,500

Re: char to num

What numeric value to expect from FA09, AA20 or AS34? The first two could be considered HEX which SAS can read but the last not. If you want to get rid of the letters before the conversion then

new_a = input(compress(a,'A',' '),4.);

might work which says to replace all alphabetic characters, 'A' code, with spaces ' '

Ask a Question
Discussion stats
  • 1 reply
  • 186 views
  • 0 likes
  • 2 in conversation