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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.