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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1 reply
  • 795 views
  • 0 likes
  • 2 in conversation