Hello everyone,
I am facing some trouble when I want to convert a character variable to a numeric one.
At start, my variable "A" is character such like :
A
---------
63,4 M€
14 866 M€
I used the compress function to have my have my variable appearing as following :
A
---------
119
63.4
14866
and so on...
Then I tried to convert it, I tried both input function and the "not rigourous" technique of multiply it by 1.
Each time I got the same error message saying :
Invalid numeric data, A='119.' , at line 16 column 6.
and my new variable B (supposedly numeric) has only missing values...
Could you help me try to figure this out please ?
Thanks a lot
could you share
the complete log part or your code for the coversion
Thank you mohamed
Here is my code (with the *1 technique) :
data test ; set figures ;
CA = A*1;
run;
In fact, in the log, it seems sas sees the data as e.g. "119." because it reads it like that (in the log) : 119€
But the € doesn't appear in my table ! I even ran a compress function before to suppress the € !
I have a way to do what I want (I substr a string as (length(myvariable)-1) and then *1) but it is not very good.
So if you have a solution to handle that invisible € sign, it would be great !
Thanks
It look like your data set examples have problem,
A
---------
63,4 M€
14 866 M€
does it contain spaces and the currency spaced from the value.
Does your data look like this? Or please give well typed sample of your dataset?
Might work (you could check for better informats):
Data A;
Input X $20.;
X_Num=Input(Compress(Substr(X,1,Length(X)-2)),Numx20.);
Datalines;
63,4 M€
14 866 M€
;
Run;
Try similar kind of stuff in your code:
data B;
input x2 $ ;
datalines;
36.2
4.2
14899
;
run;
data c;
set B;
x3=input(x2,best8.);
run;
proc contents data=c;
run;
data have;
Input val $10.;
datalines;
119 M€
634 M€
14866 M€
;
DATA WANT;
SET HAVE;
REMOVE_CHAR = COMPRESS(VAL,'MA');
NUMONLY = INPUT(REMOVE_CHAR,5.);
I have used same COMPRESS and INPUT functions, but I didn't get any error
Try this..
data a;
input x $20.;
datalines;
63,4 M€
14 866 M€
;
run;
data b;
set a;
y=input(compress(x,'123456789','k'),8.);
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.