I want to convert a string to number in a SAS SQL PROC.
The oracle-sql functioncs as TO_NUMBER()
or INT()
do not work.
I also tried the CAST(<my string> AS <target type>)
function but it does not recognize the target type INT or INTEGER.
Asked
Active
Viewed 2.3k times
3

paolof89
- 1,319
- 5
- 17
- 31
-
Have you tried "input"? – D. O. Aug 23 '18 at 15:33
-
Not yet, I just discoverd which is the sql language used in SAS SQL PROC https://stackoverflow.com/questions/51981079/sas-what-is-the-sql-language-used-in-a-proc-sql – paolof89 Aug 23 '18 at 15:35
-
1You have a string st = "1234" ==> convert it to number : input(st, 4.). 4. is the size of the number. – D. O. Aug 23 '18 at 15:39
1 Answers
3
Probably the best way would be to use:
input(your_string_variable, best.) as your_new_numeric_variable
You need to replace your_string_variable and your_new_numeric_variable appropriately. Best. is SAS format ("informat", to be exact) that tries to read in as many reasonable numeric formats as possible, it will work in majority of cases whether representation of a number you have. Still it makes sense to review the results or find a more specific format if you're interested in controlling the input.