BookmarkSubscribeRSS Feed
NewUsrStat
Pyrite | Level 9

Hi guys, 

suppose to have the following:

data DB;
input ID :$20. Admission :date09. Discharge :date09. Index1;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2017 25JAN2017 0 
0001 22FEB2018 03MAR2018 0 
0001 30JAN2019 04MAR2019 0 
0001 30JAN2019 04MAR2019 1 
0001 25DEC2020 02JAN2021 0 
0002 15JAN2014 29JAN2014 1 
0002 01FEB2015 10FEB2015 0 
0002 01FEB2015 10FEB2015 0 
0003 22MAR2019 23MAR2019 1 
0003 22MAR2019 23MAR2019 0
0003 02JUL2019 28AUG2019 0
0004 01SEP2022 15SEP2022 1
0004 02DEC2023 05DEC2023 1
;run;

 

Is there a way to get the following? In other words I need to remove duplicated rows (identical admission-discharge date) and retain the inly one where Index1 = 1. I tried with proc sort to order by the date and the Index1 (descending) without success. Thank you in advance!

data DB1;
input ID :$20. Admission :date09. Discharge :date09. Index1;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2017 25JAN2017 0 
0001 22FEB2018 03MAR2018 0 
0001 30JAN2019 04MAR2019 1 
0001 25DEC2020 02JAN2021 0 
0002 15JAN2014 29JAN2014 1 
0002 01FEB2015 10FEB2015 0 
0003 22MAR2019 23MAR2019 1   
0003 02JUL2019 28AUG2019 0              
0004 01SEP2022 15SEP2022 1            
0004 02DEC2023 05DEC2023 1
;run;

 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

May we assume there is exactly one record which has index=1 for duplicated rows? Is this record with index=1 always the second record of the duplicated records? Are there ever triplicates or quadruplicates?

--
Paige Miller
NewUsrStat
Pyrite | Level 9
I just edited the post with all possible cases. Thank you very much!
PaigeMiller
Diamond | Level 26

@NewUsrStat wrote:
I just edited the post with all possible cases. Thank you very much!

While that works in this case, in general we want data and the proper output (which you have provided), but also an explanation in words so we don't have to take our time to figure out what is happening and possibly getting it wrong. You already know, please share what you know with us. Please in the future, tell us what the logic is to go from input data to output data.

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 550 views
  • 0 likes
  • 3 in conversation