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-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 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
  • 1002 views
  • 1 like
  • 2 in conversation