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

Hello! 

 

I am running my head into a wall trying to figure out how to remove select duplicates from my dataset.  I want to track locations by a unique identifier, but I dont want to include repeat data from consecutive entries from the same location.  Here is an example of the data I have: 

 

ID       coll_Dt         Fac

1        1/12/17         A

1        1/20/17         A

1        5/6/17           B

1        6/5/17           A 

1        7/8/17           C

2        1/26/17         B

2        2/5/17           B

2        4/15/17         C

2        5/2/17           C 

2        5/29/17         B

3        2/20/17          A

3        4/19/17          B

3        5/16/17          B

3        6/8/17            C

3         8/1/17           A

 

And this is what I would like the location to look like:  (the entries in bold above removed)

 

ID       coll_dt         Fac

1        1/12/17         A

1        5/6/17           B

1        6/5/17           A 

1        7/8/17           C

2        1/26/17         B

2        4/15/17         C

2        5/29/17         B

3        2/20/17         A

3        4/19/17         B

3        6/8/17           C

3         8/1/17          A

 

 Nodupkey doesnt work becuase I want to keep duplicate locations for the same ID#- just not when they appear consecutively.  I have tried using: 

data a; set a; 

by id coll_dt fac; 

if first.fac; 

run; 

but that doesnt seem to work either. 

 

Please help! 

 

Thank you 🙂 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

data want;

set a;

by id fac NOTSORTED coll_dt ;

if first.fac;

run;

View solution in original post

4 REPLIES 4
Reeza
Super User

I think you need the NOTSORTED option.

 

data a; set a; 
by id coll_dt fac NOTSORTED; 
if first.fac; 
run; 
kaythth
Fluorite | Level 6

That did not work either, sadly 😞 

ballardw
Super User

data want;

set a;

by id fac NOTSORTED coll_dt ;

if first.fac;

run;

kaythth
Fluorite | Level 6

Thank you!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 1126 views
  • 3 likes
  • 3 in conversation