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.);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.