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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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