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

I have a dataset with patient_type=living and patient_type=deceased, as well as a column for match_ID.

 

I want to keep only observations where patient_type=living and patient_type=deceased have the same match_ID, and exclude everything else.

 

For example,

 

Key     Px_Type   Match_ID

1115    L               0001a

1116    D              0001a

1117    D              0004b

1118    L               0003b

 

I want to keep observations 1115 (L) and 1116 (D) since they have the same match_ID. Is there a way to approach this in SAS?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input Key     Px_Type $  Match_ID $;
cards;
1115    L               0001a
1116    D              0001a
1117    D              0004b
1118    L               0003b
;
run;

proc sql;
select *
 from have
  group by  Match_ID
   having count(distinct  Px_Type) ne 1;
quit;

View solution in original post

3 REPLIES 3
RW
SAS Employee RW
SAS Employee

If your data is sorted then you could try a statement like this

 

if compress(Match_ID) eq lag(compress(Match_ID)) and compress(Px_Type) in ( "D","L") then output ;

ballardw
Super User

Is there other data that has to be preserved? If so, what exactly would the result look like?

Ksharp
Super User
data have;
input Key     Px_Type $  Match_ID $;
cards;
1115    L               0001a
1116    D              0001a
1117    D              0004b
1118    L               0003b
;
run;

proc sql;
select *
 from have
  group by  Match_ID
   having count(distinct  Px_Type) ne 1;
quit;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 3 replies
  • 1717 views
  • 3 likes
  • 4 in conversation