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?
Updated my Datalines statement.
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 |
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;
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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.