I have the following data
id dx_dt rx_dt
1 1/1/2005
2 3/4/2005
2 4/4/2006
2 5/5/2007
I want to find the second minimum date so the output I am looking for id 2 is
4/4/2006
And is dx_dt an actual SAS numeric date? And what is rx_dt? This is where posting test data in the form of a datastep helps avoid these basic questions which make us guess. So my guess is based on dx_dt being SAS numeric date.
proc sort data=have out=want; by id descending dx_dt; run; data want; set want; retain cnt; by id; cnt=ifn(first.id,1,cnt+1); if cnt=2 then output; run;
And is dx_dt an actual SAS numeric date? And what is rx_dt? This is where posting test data in the form of a datastep helps avoid these basic questions which make us guess. So my guess is based on dx_dt being SAS numeric date.
proc sort data=have out=want; by id descending dx_dt; run; data want; set want; retain cnt; by id; cnt=ifn(first.id,1,cnt+1); if cnt=2 then output; run;
Thank you both!
data have;
input id dx_dt : mmddyy10.;
format dx_dt mmddyy10.;
cards;
1 1/1/2005
2 3/4/2005
2 4/4/2006
2 5/5/2007
;
run;
proc sql;
create table want as
select *
from (
select * from have group by id having dx_dt ne max(dx_dt)
)
group by id
having dx_dt = max(dx_dt);
quit;
data have;
input id dx_dt :mmddyy10. ;
format dx_dt mmddyy10. ;
cards;
1 1/1/2005
2 3/4/2005
2 4/4/2006
2 5/5/2007
;
proc rank data=have out=want(where=(dx_dt_rank=2)) ties=low ;
by id;
var dx_dt;
ranks dx_dt_rank;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.