BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
learn2
Fluorite | Level 6

This is a previously unanswered question, hoping someone can help!

 

If I have the following data let’s say with some duplicate injury dates. My goal is to keep the most severe of the duplicate injury dates along with the other unique injury records. The hierarchy is as follows: Home(least severe)<Clinic<Hospital(more severe). So I would keep only the Clinic observation for ID 1, but for ID 2 I would keep the Clinic on the Feb 1st injury date (as it is more severe than Home for the same injury date) and the Feb 6th date since it’s another injury date and not a duplicate. How do I code this?

 

ID

Injury date

Location of injury

1

Jan02,2007

Home

1

Jan02, 2007

Clinic

2

Feb01,2000

Home

2

Feb06,2000

Hospital

2

Feb01,2000

Clinic

1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

You are correct that the question has been asked before the solution below has changes that take into account your requirements for the date criteria.

 

 

data have;
input ID $ Injurydate:$20. Locationofinjury $;
infile cards dlm=' ';
cards;
1 Jan02,2007 Home
1 Jan02,2007 Clinic
2 Feb01,2000 Home
2 Feb06,2000 Hospital
2 Feb01,2000 Clinic
;


data help;
set have;
if Locationofinjury="Home" then severity=1;
else if Locationofinjury="Clinic" then severity=2;
else if Locationofinjury="Hospital" then severity=3;
else severity=.;
run;

proc sort data=help;
by ID injurydate severity;
run;

data want(drop=severity);
set help;
by ID injurydate severity;
if last.injurydate;
run;

 


 

View solution in original post

1 REPLY 1
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

You are correct that the question has been asked before the solution below has changes that take into account your requirements for the date criteria.

 

 

data have;
input ID $ Injurydate:$20. Locationofinjury $;
infile cards dlm=' ';
cards;
1 Jan02,2007 Home
1 Jan02,2007 Clinic
2 Feb01,2000 Home
2 Feb06,2000 Hospital
2 Feb01,2000 Clinic
;


data help;
set have;
if Locationofinjury="Home" then severity=1;
else if Locationofinjury="Clinic" then severity=2;
else if Locationofinjury="Hospital" then severity=3;
else severity=.;
run;

proc sort data=help;
by ID injurydate severity;
run;

data want(drop=severity);
set help;
by ID injurydate severity;
if last.injurydate;
run;

 


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 776 views
  • 0 likes
  • 2 in conversation