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!
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.