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!
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 ' '
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.