I have a table with Latitude and Longitude saved in character format. When I run this code I get this note:
Invalid numeric data, Longitude='-80.192798.' , at line 65 column 20.
the data had strange characters in it. This fixed it: Longitude =Compress(tranwrd(Longitude,'0A'x,' '),,'kw')
Whenever you encounter ERRORs or WARNINGs, post the complete (all code and messages) log of the failing step by copy/pasting it into a window opened with this button:
Longitude is a character variable containing something which prevents automatic conversion to numeric. Display it with a $HEX format of sufficient length to see which characters are contained.
Numbers can only contain one decimal point.
'-80.192798.'
has two decimal points.
the data had strange characters in it. This fixed it: Longitude =Compress(tranwrd(Longitude,'0A'x,' '),,'kw')
@KRusso wrote:
the data had strange characters in it. This fixed it: Longitude =Compress(tranwrd(Longitude,'0A'x,' '),,'kw')
So what is the goal of those function calls?
You convert the linefeed into a space. Then you eliminated all of the non-printable characters, even the linefeeds you just remove. So why not just remove the TRANWRD() function call?
Or did you mean to convert non-breaking spaces ('A0'X) to spaces first? That character will NOT be removed by COMPRESS() as apparently COMPRESS() thinks it IS a printable character.
Why not just keep the digits and other characters used to represent numbers?
lng=input(compress(longitude,'+-.E','kd'),32.);
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.