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.);
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.