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

Hi,

 

I have the following dataset:

 

RECNR         OPR  

123                XDFW

123                EDG03

1245              XDFW

1245              EDG03

1245              KFE011

1245              RTF00

 

So I have several observations with equal RECNR but different OPR value. 

 

I want to keep observations with equal RECNR (e.g. 1245) that have the OPR values of EDG03 AND XDFW. 

 

Can anyone help?

 

Thanks a lot! 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

One way:

data want;
set have;
by recnr;
where opr in ('XDFW', 'EDG03');
if first.recnr=0 or last.recnr=0;
run;

It's probably clear to you (but not to me) whether or not you want to keep other OPR values when the RECNR contains one of the values you are looking for.  This code keeps only the two values you specified, and requires there to be more than 1 observation containing a value in the list.

View solution in original post

1 REPLY 1
Astounding
PROC Star

One way:

data want;
set have;
by recnr;
where opr in ('XDFW', 'EDG03');
if first.recnr=0 or last.recnr=0;
run;

It's probably clear to you (but not to me) whether or not you want to keep other OPR values when the RECNR contains one of the values you are looking for.  This code keeps only the two values you specified, and requires there to be more than 1 observation containing a value in the list.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 578 views
  • 0 likes
  • 2 in conversation