Hi I have a question that I am struggling with: I have three variables of interest that I would like help with. I would like to create a variable that captures the time from when the patient was first transfered to discharge for Med/Surgical unit. Something like:

transfer_datetime transfer_type unit_type
01/15/19 03:05 transfer other
01/17/19 01:20 discharge
01/20/19 12:25 transfer other
admit Med/Surg
transfer Med/Surg
transfer Med/surg
discharge


What I would like is a variable that shows the time between the first transfer and the discharge, for med/surgical unit type only (the discharge has no unit_type because it is discharge), and not for the "other". May you please assist with this?