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

I have a table that has ID, Code, and Date. Each ID can have multiple codes, each occurring on a different date. I only want the ID & Code for the most recent date.

 

How do I do this?

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

Two (of many more perhaps) choices:

  1.  First sort, like in your post title. The a new sort on ID alone, and nodupkey.
  2. Using Join transformation, Group By on ID, having date = max(date)
Data never sleeps

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20

Two (of many more perhaps) choices:

  1.  First sort, like in your post title. The a new sort on ID alone, and nodupkey.
  2. Using Join transformation, Group By on ID, having date = max(date)
Data never sleeps
GregG
Quartz | Level 8

Thank you! I was thinking about the double sort, but wasn't sure if the second sort would re-sort (and wipe out the first).

 

Ended up going with the join transformation option instead.

 

Thank you again!

LinusH
Tourmaline | Level 20
Happy to help 😊
But the double sort should be reliable. The PROC SORT doc states that NODUPKEY will keep the first row encountered for each by group.
What to chose is just matter of taste. The SQL alternative could perform better if your source table is stored in a powerful RDBMS server.
Data never sleeps

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1188 views
  • 1 like
  • 2 in conversation