BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dwsmith
Obsidian | Level 7

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.
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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.

View solution in original post

1 REPLY 1
FreelanceReinh
Jade | Level 19

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1173 views
  • 0 likes
  • 2 in conversation