BookmarkSubscribeRSS Feed
nickspencer
Obsidian | Level 7
I am trying to bring in latest record from teradata based on two IDs, but without grouping them.
Both these IDs have been reassigned to each other so I want to pick up the latest.
I do not want to have duplicates by any IDs.
Have:
ID1 ID2 date
123 987 12/01/2020
123 654 05/10/2020
345 999 01/20/2020
456 999 12/20/2020
231 789 12/10/2020
231 789 12/21/2020

Want:
ID1 ID2
123 987
456 999
231 789

Since the data is in teradata, might be efficient to use sql/teradata sql instead of data step? Please advice.
1 REPLY 1
SASKiwi
PROC Star

Something similar to this should do it:

libname TD teradata noprompt = "< Teradata connection string>" DATABASE = MyDatabase schema = MySchema; 

proc sql;
  create table Want as
  select  A.ID1
         ,A.ID2
         ,A.Date
  from TD.Have as A
  inner join 
  (select  ID1
          ,ID2
          ,max(Date) as Max_Date
   from TD.Have
   group by  ID1
            ,ID2
  ) as B
  on A.ID1 = B.ID1
  and A.ID2 = B.ID2
  and A.Date = B.Max_Date
  ;
quit;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 1059 views
  • 0 likes
  • 2 in conversation