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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 788 views
  • 0 likes
  • 2 in conversation