Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
51
Task/Haversine-formula/SAS/haversine-formula.sas
Normal file
51
Task/Haversine-formula/SAS/haversine-formula.sas
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
options minoperator;
|
||||
|
||||
%macro haver(lat1, long1, lat2, long2, type=D, dist=K);
|
||||
|
||||
%if %upcase(&type) in (D DEG DEGREE DEGREES) %then %do;
|
||||
%let convert = constant('PI')/180;
|
||||
%end;
|
||||
%else %if %upcase(&type) in (R RAD RADIAN RADIANS) %then %do;
|
||||
%let convert = 1;
|
||||
%end;
|
||||
%else %do;
|
||||
%put ERROR - Enter RADIANS or DEGREES for type.;
|
||||
%goto exit;
|
||||
%end;
|
||||
|
||||
%if %upcase(&dist) in (M MILE MILES) %then %do;
|
||||
%let distrat = 1.609344;
|
||||
%end;
|
||||
%else %if %upcase(&dist) in (K KM KILOMETER KILOMETERS) %then %do;
|
||||
%let distrat = 1;
|
||||
%end;
|
||||
%else %do;
|
||||
%put ERROR - Enter M on KM for dist;
|
||||
%goto exit;
|
||||
%end;
|
||||
|
||||
data _null_;
|
||||
convert = &convert;
|
||||
lat1 = &lat1 * convert;
|
||||
lat2 = &lat2 * convert;
|
||||
long1 = &long1 * convert;
|
||||
long2 = &long2 * convert;
|
||||
|
||||
diff1 = lat2 - lat1;
|
||||
diff2 = long2 - long1;
|
||||
|
||||
part1 = sin(diff1/2)**2;
|
||||
part2 = cos(lat1)*cos(lat2);
|
||||
part3 = sin(diff2/2)**2;
|
||||
|
||||
root = sqrt(part1 + part2*part3);
|
||||
|
||||
dist = 2 * 6372.8 / &distrat * arsin(root);
|
||||
|
||||
put "Distance is " dist "%upcase(&dist)";
|
||||
run;
|
||||
|
||||
%exit:
|
||||
%mend;
|
||||
|
||||
%haver(36.12, -86.67, 33.94, -118.40);
|
||||
Loading…
Add table
Add a link
Reference in a new issue