Identifying earliest event within a sequence of events

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Identifying earliest event within a sequence of events

Hello,

I have 3 variables of interest:

mrn < - unique to each individual

fin < - unique to each patient visit

adm_dat < - date of admission corresponds to fin, each adm_dat has one fin

data set looks like this:

mrnfinadm_dat
8420802852800012458348/24/12
8420802852800012458348/24/12
8420802851000094928391/13/13
3766079780001814412961/4/06

what I want is the first admission date per mrn with a corresponding fin. My code produces this:

mrnfinadm_dat
8420802852800012458348/24/12
8420802851000094928391/13/13
3766079780001814412961/4/06

Which is almost there, I just need to add something else to the code to get this:

mrnfinadm_dat
8420802852800012458348/24/12
3766079780001814412961/4/06

my code:

proc sort data = have; by adm_dat fin; run;

data want;

     set have;

     by adm_dat fin;

     retain firstdate;

     if first.fin and last.fin then do;

          firstdate = adm_dat;

          lastdate = adm_dat;

          output;

     end;

     else if first.fin then first date = arm_dat;

     else if last.fin then do;

          lastdate = adm_dat;

          output;

     end;

run;

    

What comes next?

Thank You


Accepted Solutions
Solution
‎04-11-2013 04:54 PM
Super User
Posts: 17,823

Re: Identifying earliest event within a sequence of events

Unless your want is different than stated does the following work:

proc sort data = have; by mrn adm_dat ; run;

data want;

set have;

by mrn;

if first.mrn;

run;

View solution in original post


All Replies
Solution
‎04-11-2013 04:54 PM
Super User
Posts: 17,823

Re: Identifying earliest event within a sequence of events

Unless your want is different than stated does the following work:

proc sort data = have; by mrn adm_dat ; run;

data want;

set have;

by mrn;

if first.mrn;

run;

Contributor
Posts: 20

Re: Identifying earliest event within a sequence of events

Thank you, this is so much easier.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 235 views
  • 0 likes
  • 2 in conversation