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-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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