BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10

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 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
  

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
  
lillymaginta
Lapis Lazuli | Level 10

Thank you both! 

Ksharp
Super User
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;
novinosrin
Tourmaline | Level 20
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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 4 replies
  • 2693 views
  • 1 like
  • 4 in conversation