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

Hi all!

 

I am incredibly new to SAS Code, and I appreciate if you can help me on below matter:

 

Here is the code for the data:

 

DATA TEMP;
INPUT @1 Ref 7. 
	  @9 ID 5. 
	  @14 LockerNo 12.
	  @28 Date ddmmyy10.
	  @39 Cust_Name $ 14.;
DATALINES;
4511445 1952  123456789123 08/12/2001 XYZ PRODUCTION 
4545154 1952  987654321987 26/09/2001 DEF Co.        
7895412 96321 456123789456 12/10/2000 ABC AGENCY     
7895412 96321 123789654753 21/12/2000 ABC AGENCY     
5451654 96321 125874934589 05/10/2006 ABC AGENCY     
5451654 96321 123467984352 23/11/2004 ABC AGENCY     
5451654 96321 785645464644 17/01/2005 ABC AGENCY     
5451654 96321 156454654546 11/11/2004 GHI Enterprise    
;
RUN; 

proc sort data=have out=have;
  by id DESCENDING date;
run;

data want;
  set have;
  by id;
  retain final;

  if first.id then
    final=ref;
run;

What I want to achieve is:

 

         Create a new table (named MASTER) for records that shares the same ID, but different CUST_NAME. 

         It will record the REF with the latest DATE and Cust_Name which differ from the REF with the latest DATE

 

The new table, MASTER will look like below:

RefIDLockerNoDateCust_NameFinal
451144519521234567891238/12/2001XYZ PRODUCTION4511445
4545154195298765432198726/9/2001DEF Co.4511445
5451654963211258749345895/10/2006ABC AGENCY5451654
54516549632115645465454611/11/2004GHI Enterprise5451654

 

I am using SAS Enterprise Guide 7.1 

Appreciate your help on this!

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16
proc sort data=temp;
by id Cust_Name date ;
run;

data want;
set temp;
by id Cust_Name date ;
if last.cust_name;
run;
Thanks,
Jag

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16
proc sort data=temp;
by id Cust_Name date ;
run;

data want;
set temp;
by id Cust_Name date ;
if last.cust_name;
run;
Thanks,
Jag

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1190 views
  • 1 like
  • 2 in conversation