BookmarkSubscribeRSS Feed
woo
Barite | Level 11 woo
Barite | Level 11

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!


1 REPLY 1
ballardw
Super User

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 ' '

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 695 views
  • 0 likes
  • 2 in conversation