I looked at https://communities.sas.com/t5/Base-SAS-Programming/Calculating-pair-wise-distances-using-the-geodis... but the code isn't well documented so I am not entirely sure what is going on.
I have a data set with millions of lat long. Let's call it loc_dist.
data loc_dist (keep = ser_no EQP_GPS_SPEC_LAT_CORD EQP_GPS_SPEC_Long_CORD);
set mttt.locs_machines;
recid = _n_;
run;
data results (keep = ser_no gdist);
set loc_dist nobs = nobs;
if _n_ = 1 then do;
if 0 then
set loc_dist(keep = EQP_GPS_SPEC_LAT_CORD EQP_GPS_SPEC_Long_CORD
rename = (EQP_GPS_SPEC_LAT_CORD = lat EQP_GPS_SPEC_Long_CORD = long));
_rc = h1.definekey('recid');
_rc = h1.definedata('lat', 'long');
_rc = h1.definedone();
end;
do i = (recid + 1) to nobs;
_rc = h1.find(key:_i);
gdist = geodist(EQP_GPS_SPEC_LAT_CORD, EQP_GPS_SPEC_Long_CORD, lat, long);
output;
end;
run;
However, I get the following error:
830 _rc = h1.definekey('recid');
------------
557
ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.
ERROR 557-185: Variable h1 is not an object.
I think, you just forgot to copy (and adapt) the declaration of the hash object you want to use. So, please insert the following statement before the line which contains "h1.definekey":
dcl hash h1(dataset:'loc_dist(keep=recid EQP_GPS_SPEC_LAT_CORD EQP_GPS_SPEC_Long_CORD
rename=(EQP_GPS_SPEC_LAT_CORD=lat EQP_GPS_SPEC_Long_CORD=long))');
Also, you may want to keep more variables than just SER_NO and GDIST in dataset RESULTS in order to uniquely identify the pair of points the distance GDIST belongs to.
EDIT: One more mistake: i should read _i in the "do i= ..." loop.
I think, you just forgot to copy (and adapt) the declaration of the hash object you want to use. So, please insert the following statement before the line which contains "h1.definekey":
dcl hash h1(dataset:'loc_dist(keep=recid EQP_GPS_SPEC_LAT_CORD EQP_GPS_SPEC_Long_CORD
rename=(EQP_GPS_SPEC_LAT_CORD=lat EQP_GPS_SPEC_Long_CORD=long))');
Also, you may want to keep more variables than just SER_NO and GDIST in dataset RESULTS in order to uniquely identify the pair of points the distance GDIST belongs to.
EDIT: One more mistake: i should read _i in the "do i= ..." loop.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.