BookmarkSubscribeRSS Feed
sas_student1
Quartz | Level 8

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. 

 

Clientadmit_datedsch_dateadmit_date1dsch_date1
A6/28/20023/30/20156/28/20027/12/2019
A6/28/20023/30/20156/28/20027/12/2019
A6/28/20023/30/20156/28/20027/12/2019
A3/30/20157/12/20196/28/20027/12/2019
B1/9/19988/21/20131/9/1998.
B8/21/2013.1/9/1998.
1/29/20082/21/20081/29/2008.
C2/21/20082/15/20231/29/2008.
C2/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!

 

 

 

1 REPLY 1
Tom
Super User Tom
Super User

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
;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 442 views
  • 0 likes
  • 2 in conversation