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;
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!
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.