I've a value as '0,50708683901377' character and I want to convert it to numeric. After numeric conversion, I want the value as same as before I convert.
I tried with the Format 21.4 and also NUMX18.10 but it's not producing the desired results. Any help with the Format to produce the desired value?
What I tried is,
(input(H,Best32.)) as Value length = 8 format = 21.4 informat = 21.4
Desired result is, 0,50708683901377 as numeric
It seems that the comma inside the number is for decimal sign (0,5 = a half).
in your case the number = '0,50708683901377' has 14 decimal digits.
Try using format 21.14
21.14 means 21 characters in whole, including the comma with 14 decimal digits, which leaves 6 characters for the integer. (6+1+14 = 21).
/* https://documentation.sas.com/?cdcId=vdmmlcdc&cdcVersion=8.1&docsetId=leforinforref&docsetTarget=n056hzkipsxpcbn11ww9i9i47l0h.htm&locale=en */
data test_comma;
format h commax16.14;
h=input('0,50708683901377',comma16.14);
put h=;
run;
As you have a decimal comma you need to use the "X" formats (commax, numx etc.).
In this case use NumX32.14.
Even though NumX16.14 would be enough to handle the width of this string the next value could be '65342522,50708683901377' which would require NumX23.14.
Data char2num;
H = '0,50708683901377';
Value = Input(H,numX32.14);
Format Value NumX32.14;
Put Value NumX32.14 ;
Run;
Do not use fractional parts in informats. If no comma is present in the string, the informat will first divide by 10**(fractional part), and then apply the format. A string of "1" would then result in 1e-14.
Simply do
input(H,commax32.) as Value length = 8 format = 21.4
it is not necessary to define an informat; defined informats are only needed when reading from external data.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.