I have a dataset of patients who are admitted and then transferred to another clinic. Sometimes they may get transferred a few times. I would like to get their first admission date and not the transferred date. For example I have the table with admit_date and dsch_date. You will notice that at times the admit_date repeats for a few records (see client A) but then there is a new record with a new admit_date that is the same as the previous dsch_date. What I would like to do is get the first admit date and last discharge date if it is available. If the dsch_date is missing then the client is still in treatment. I would like to get admit_date1 and dsch_date1 column.
| Client | admit_date | dsch_date | admit_date1 | dsch_date1 |
| A | 6/28/2002 | 3/30/2015 | 6/28/2002 | 7/12/2019 |
| A | 6/28/2002 | 3/30/2015 | 6/28/2002 | 7/12/2019 |
| A | 6/28/2002 | 3/30/2015 | 6/28/2002 | 7/12/2019 |
| A | 3/30/2015 | 7/12/2019 | 6/28/2002 | 7/12/2019 |
| B | 1/9/1998 | 8/21/2013 | 1/9/1998 | . |
| B | 8/21/2013 | . | 1/9/1998 | . |
| C | 1/29/2008 | 2/21/2008 | 1/29/2008 | . |
| C | 2/21/2008 | 2/15/2023 | 1/29/2008 | . |
| C | 2/15/2023 | . | 1/29/2008 | . |
Here is the sas code for the table I have:
data have;
input Client:$1. admit_date:mmddyy10. dsch_date:mmddyy10. ;
format admit_date dsch_date mmddyy10.;
datalines;
A 6/28/2002 3/30/2015
A 6/28/2002 3/30/2015
A 6/28/2002 3/30/2015
A 3/30/2015 7/12/2019
B 1/9/1998 8/21/2013
B 8/21/2013 .
C 1/29/2008 2/21/2008
C 2/21/2008 2/15/2023
C 2/15/2023 .
;
run;Thank you!
Aren't those just the MIN and MAX, respectively, or the two variables you already have?
create table want as
select *
,min(admit_date) as admit_date1 format=mmddyy10.
,max(dsch_date) as dsch_date1 format=mmddyy10.
from have
group by Client
;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.