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.

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