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
;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 237 views
  • 0 likes
  • 2 in conversation