BookmarkSubscribeRSS Feed
shiv999
Calcite | Level 5
Hi guys
My data is like
Id. Name $ 10 Doj :date9. dot:date9.;
11235 Jim 12jul2017 01auj2018
11235 Jim. 12jul2019 01auj2019
11235 Jimcarod 12jan2020 01feb2020
11235 Jimcarod 12jul2020 01auj2020

My code should replace all the row with name Jimcarod . As its is the latest entry and have same id




2 REPLIES 2
PaigeMiller
Diamond | Level 26

Duplicate question. @shiv999 please don't post a question more than once. Everyone should respond at https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/td-p/696461

--
Paige Miller
Ksharp
Super User

Assuming dataset have beed sort by ID , Date.

 

data have;
input Id  Name $  Doj :date9. dot:date9.;
format doj dot date9.;
cards;
11235 Jim 12jul2017 01aug2018
11235 Jim. 12jul2019 01aug2019
11235 Jimcarod 12jan2020 01feb2020
11235 Jimcarod 12jul2020 01aug2020
;

data want;
 do until(last.id);
  set have;
  by id;
 end;
 _name=name;
do until(last.id);
  set have;
  by id;
  name=_name;output;
 end;
 drop _name;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 704 views
  • 0 likes
  • 3 in conversation