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

How can i deduplicate a dataset by ID1 and ID2, if I have the next structure:

 

ID1    ID2  DATE           VALUE

1000 10    31JAN2016     5

1000 10    26FEB2016     6

1000 10    31MAR2016    7

 

The result that I expectedis:

ID1    ID2 DATE           VALUE

1000 10    31MAR2016    7

(Which is the most current date according to the date)

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use proc sort.

 

proc sort data=have;

by id id2 date; run;

 

data want;

set have;

by id id2;

if last.id2;

run;

 

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Use proc sort.

 

proc sort data=have;

by id id2 date; run;

 

data want;

set have;

by id id2;

if last.id2;

run;

 

 

Angel_Saenz
Quartz | Level 8
Thank you it works very good just a question in:
if last.id2;
why var id2? Can be any variable?
Reeza
Super User

No, it has to be a variable listed in the BY statement.

 

And it picks the last of that group, based on your specifications, this is what was required, but you can modify it to fit your needs, if you have more variables or something.

 

You can review the documentation on how BY groups are processed and the FIRST/LAST variables and how they're calculated.

I find the examples and illustrations here helpful:

http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0xu93fy5eemkyn1p6mj...

 

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
  • 3 replies
  • 1046 views
  • 2 likes
  • 2 in conversation