DATA Step, Macro, Functions and more

Pairwise geodist calculation

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

Pairwise geodist calculation

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.

Accepted Solutions
Solution
‎03-07-2016 07:25 AM
Trusted Advisor
Posts: 1,115

Re: Pairwise geodist calculation

[ Edited ]

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


All Replies
Solution
‎03-07-2016 07:25 AM
Trusted Advisor
Posts: 1,115

Re: Pairwise geodist calculation

[ Edited ]

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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