BookmarkSubscribeRSS Feed
farshidowrang
Quartz | Level 8

Hi,

 

I need to convert UTM-X and UTM-Y to Latitude and Longitude in meter for Datum  ED50 and Zone 31N:

 

UTM-X = 513932.02

UTMY = 6266840.53

 

the answer should be 

LAT = 56.54444957 

LONG= 3.2265688702

 

I have used the formula here:

 

https://communities.sas.com/t5/SAS-Communities-Library/Convert-LAT-LONG-to-UTM-and-back/ta-p/221779

 

However, in this formula 

 

datum=WGS84

zone = 18N

 

I can change zone but when I change datum to ED50 I get trouble with proj4.

 

What is proj4?

How can I change it to be fitted for ED50???

 

I would be very grateful if you could help me with this

6 REPLIES 6
ballardw
Super User

Please provide the exact code that you used and the data set used as data step code. Paste both into a code box opened using the forum's {I} or "running man" icons.

 

I am not even going to guess how someone actually modified example code, as in the link provided, and then reports an issue.

It may also help to describe the trouble when changing the datum.

 

PROJ4 is the set of calculations to do the Lat Long conversion to Mercator coordinates.

farshidowrang
Quartz | Level 8

Hi,

 

Thank you for your fast reponse. Here is my codes. They are working however, I want them for ED50 and not WGS84:

 

 

%macro latLong2UTM(DSN,lat=LAT,long=LONG,zone=18N);
data _null_;
no = compress("&zone", , "as");
if findc("&zone", "sS") = 0 then
call symputx("to", cats("+proj=utm +datum=WGS84 +units=m +no_defs +zone=", no));
else call symputx("to", cats("+proj=utm +datum=WGS84 +units=m +no_defs +south +zone=", no));
run;
proc gproject latlon degrees
project = proj4
from = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
to = "&to"
data = &DSN(rename=(&lat=LAT &long=LONG))
out = &DSN;
id;
run;
%mend;

%macro UTM2latLong(DSN,y=Y,x=X,zone=18N);
data _null_;
no = compress("&zone", , "as");
if findc("&zone", "sS") = 0 then
call symputx("from", cats("+proj=utm +datum=WGS84 +units=m +no_defs +zone=", no));
else call symputx("from", cats("+proj=utm +datum=WGS84 +units=m +no_defs +south +zone=", no));
run;
data _UTM2latLong;
set &DSN;
_oldX = &x;
_oldY = &y;
rename &x=X &y=Y;
run;
proc gproject
project = proj4
to = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
from = "&from"
data = _UTM2latLong
out = _UTM2latLong;
id;
run;
data &DSN(drop=x y rename=(_oldX=&x _oldY=&y));
set _UTM2latLong;
lat = y;
long = x;
run;
proc sql; drop table _UTM2latLong; quit;
%mend;

data test;
infile datalines delimiter=',';
input lat long ;
datalines;
56.547480166,3.218883593
56.547518793,3.2189358171
56.547515029,3.2189742138
;

title "Original coordinates";
proc print data=test noobs; run;
%LatLong2UTM(test);

title "LatLong2UTM";
proc print data=test noobs; run;

data test2(drop=lat long);
set test;
run;

title "Original UTMs";
proc print data=test2 noobs; run;

%UTM2LatLong(test2);

title "UTM2LatLong";
proc print data=test2 noobs; run;
**************************************** */

data &DSN(drop=x y rename=(_oldX=&x _oldY=&y));
set _UTM2latLong;
lat = y;
long = x;
run;
proc sql; drop table _UTM2latLong; quit;
%mend;

ballardw
Super User

Looking in the SASHELP.PROJ4DEF data set it looks like the Name that you want is the EPSG:4154. The description says that is for ED50(ED77)

 

or possibly the TO string value of "+proj=longlat +ellps=intl +towgs84=-117,-132,-164,0,0,0,0 +no_defs"

farshidowrang
Quartz | Level 8

Dear sir,

 

Thank you very much

 

Best regards

 

Farshid

PGStats
Opal | Level 21

Proj4 is an open source coordinate projection software.

 

Looks like the proj4 from-string for ED50 UTM zone 31N should be

 

+proj=utm +zone=31 +ellps=intl +units=m +no_defs 


Look here

 

https://spatialreference.org/ref/?search=ED50

PG
farshidowrang
Quartz | Level 8

Thank you very much!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 2567 views
  • 0 likes
  • 3 in conversation