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;

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
  • 2 replies
  • 322 views
  • 0 likes
  • 3 in conversation