BookmarkSubscribeRSS Feed
imdickson
Quartz | Level 8

 

aa

I have a column where it stores GPS coordinate with degree value as below

 

Coordinate
 30°25.264 9°01.331
30°39.237 8°10.811
31°37.760 8°06.040
 31°41.190 8°06.557
 31°41.229 8°06.622
 31°38.891 8°06.281

 

I want it to be converted into Longitude and Latitude as below:

 

                    lat             long
 30.4210666666667 9.02218333333333
         30.65395 8.18018333333333
 31.6293333333333 8.10066666666667
          31.6865 8.10928333333333
         31.68715 8.11036666666667
 31.6481833333333 8.10468333333333

 

 

Below is the datalines for your usage:

 

data gps;
  input coordinate $60.;

  datalines;
30°25.264 9°01.331
30°39.237 8°10.811
31°37.760 8°06.040
 31°41.190 8°06.557
 31°41.229 8°06.622
 31°38.891 8°06.281
run;


 

I tried to research PROC GEOCODE but icannot see how it can convert it.

 

Can anyone help me on this?

7 REPLIES 7
Reeza
Super User
Can you please fix the input data? It won't run for me.
imdickson
Quartz | Level 8

Updated my Datalines statement.

ChrisNZ
Tourmaline | Level 20

Like this?

data WANT;
  input COORDINATES $60.;
  LAT=scan(COORDINATES,1,'° ')+scan(COORDINATES,2,'° ')/60;
  LON=scan(COORDINATES,3,'° ')+scan(COORDINATES,4,'° ')/60;
cards;
30°25.264 9°01.331
30°39.237 8°10.811
31°37.760 8°06.040
31°41.190 8°06.557
31°41.229 8°06.622
31°38.891 8°06.281
run;

COORDINATES LAT LON
30°25.264 9°01.331 30.4211 9.02218
30°39.237 8°10.811 30.6540 8.18018
31°37.760 8°06.040 31.6293 8.10067
31°41.190 8°06.557 31.6865 8.10928
31°41.229 8°06.622 31.6872 8.11037
31°38.891 8°06.281 31.6482 8.10468

 

Haikuo
Onyx | Level 15

Proc Geocode is not for this purpose. All you need is to convert those minutes and seconds into decimals, of course, chars to numbers as well.

 

data gps;
  input coordinate $60.;
lat=input(scan(scan(coordinate,1,' '),1,'°'),best.)+input(scan(scan(coordinate,1,' '),2,'°'),best.)/60;
long=input(scan(scan(coordinate,2,' '),1,'°'),best.)+input(scan(scan(coordinate,2,' '),2,'°'),best.)/60;
  datalines;
30°25.264 9°01.331
30°39.237 8°10.811
31°37.760 8°06.040
 31°41.190 8°06.557
 31°41.229 8°06.622
 31°38.891 8°06.281
run;
PGStats
Opal | Level 21
data want;
set gps;
latDeg = input(scan(coordinate,1,"° "), best.);
latMin = input(scan(coordinate,2,"° "), best.);
lonDeg = input(scan(coordinate,3,"° "), best.);
lonMin = input(scan(coordinate,4,"° "), best.);
lat = latDeg + latMin/60;
long = lonDeg + lonMin/60;
drop latDeg latMin lonDeg lonMin;
run;
PG
imdickson
Quartz | Level 8
Thanks everyone. I have used all the given codes and also added an additional "Seconds" for the last part of the geo_location into decimal. Once again thanks for the help very much.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 2297 views
  • 1 like
  • 5 in conversation