please try
data have;
input Id Dateofjoining :date9.;
diff=coalesce(dif(Dateofjoining),0);
if not (diff<0);
cards;
101 21Aug2018
102 22Aug2018
103 17Aug2018
104 25Aug2018
105 27Aug2018
106 18Aug2018
107 30Aug2018
;
					
				
			
			
				data have;
input Id Date : date9.;
format date date9.;
cards;
101 21Aug2018
102 22Aug2018
103 17Aug2018
104 25Aug2018
;
data want;
 set have;
 retain temp;
 if temp<date then temp=date;
  else flag=1;
  drop temp;
run;
					
				
			
			
				
			
			
			
			
			
			
			
		temp hold the max date when go through the table.
101 21Aug2018
102 22Aug2018
103 17Aug2018
100 18Aug2018
104 25Aug2018
;
103 and 100 is you want removed ?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.