BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
KRusso
Obsidian | Level 7

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.

However, when I look at the table, none of the records contain that second decimal at the end.
I've used the scan, find, compress, count to eliminate this mystery decimal at the end. But these functions do not recognize it either.
The data that originally created the dataset was in MS Access. When data was imported, there were no errors. 
 
data agenttable; 
set agenttableFromaccess (keep =  Agent Latitude Longitude); 
  FORMAT LAT LNG BEST12.; 
LAT=LATITUDE;
LNG=Longitude;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
KRusso
Obsidian | Level 7

the data had strange characters in it. This fixed it: Longitude =Compress(tranwrd(Longitude,'0A'x,' '),,'kw')

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

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:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

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.

Tom
Super User Tom
Super User

Numbers can only contain one decimal point.

'-80.192798.'

has two decimal points.

Reeza
Super User
That isn't how you convert a character variable to a numeric one. You need to use INPUT to convert it.

lat = input(latitude, best32.);
lng = input(longitude, best32.);
KRusso
Obsidian | Level 7

the data had strange characters in it. This fixed it: Longitude =Compress(tranwrd(Longitude,'0A'x,' '),,'kw')

Tom
Super User Tom
Super User

@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.);

 

 

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 516 views
  • 0 likes
  • 4 in conversation