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

HI

i have a table that has duplicate entries here is and example.

ID.      Lat.       Long

001.    0             0

001.    33.4.      -112.221

i would want to remove the duplicate that has 0 for lat and long and keep the entry  where there is a lat and long.

here is  a snippet of what I'm using

proc sort data= table1

out=table1

nodupkey;

where lat <> 0;

by  ID;

which works except it also removes some id  that's are not dups  but have a 0 in the lat and long columns ....thanks again for assistance

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Sort first descending by lat then use nodupkey. This will push the observations with values before the ones with 0.

proc sort data=have; by id descending lat;

run;

proc sort data=have nodupkey; by id;

run;

View solution in original post

4 REPLIES 4
Reeza
Super User

Sort first descending by lat then use nodupkey. This will push the observations with values before the ones with 0.

proc sort data=have; by id descending lat;

run;

proc sort data=have nodupkey; by id;

run;

Astounding
PROC Star

The possibility of negative values can make this tricky.  If you can guarantee that each ID has at most one record with all 0s, here's a way to do it:

proc sort data=have;

   by id;

run;

data want;

   merge have (where=(lat=0 and long=0))

             have (where=(lat ne 0 or long ne 0));

   by id;

run;

Good luck.

Reeza
Super User

True, but latitude and longitude have very well defined transition points to negative/positive. If I'm dealing with Canadian data for example, I know that all my latitudes will be positive.

For countries that cross boundaries another solution would be required.

Ksharp
Super User

How about this:

data have;
input ID   $   Lat       Long ;
cards;
001.    0             0
001.    33.4      -112.221
002.     0             0
;
run;
proc sort data=have;
   by id;
run;
data want;
 set have;
 by id;
 if  lat = 0 and not(first.id and last.id) then delete;
run;

Ksharp

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2385 views
  • 6 likes
  • 4 in conversation