DATA Step, Macro, Functions and more

remove duplicated pairs of variable values

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

remove duplicated pairs of variable values

I would like to remove observations where the value in 2 columns are the same (exists before). For example, pair A and B exist already so I would like to remove the fourth observation. similarly, I would like to remove the last obs as the pair B and C already exist.

student1student2treatment
ABkeep
ACkeep
ADkeep
BAremove
BCkeep
BDkeep
CAkeep
CBremove

 


Accepted Solutions
Solution
a week ago
PROC Star
Posts: 124

Re: remove duplicated pairs of variable values

Posted in reply to ducman1611

If you can live with an arbitrary order of your students in the rows, you can use SORTC to get the students in the same order everywhere. Then it is just a question of removing the duplicates (SORT with NODUPKEY):

data sorted;
  set have;
  call sortc(student1,student2);
run;

proc sort nodupkey;
  by student1 student2;
run;

View solution in original post


All Replies
Solution
a week ago
PROC Star
Posts: 124

Re: remove duplicated pairs of variable values

Posted in reply to ducman1611

If you can live with an arbitrary order of your students in the rows, you can use SORTC to get the students in the same order everywhere. Then it is just a question of removing the duplicates (SORT with NODUPKEY):

data sorted;
  set have;
  call sortc(student1,student2);
run;

proc sort nodupkey;
  by student1 student2;
run;
Highlighted
Super User
Super User
Posts: 8,181

Re: remove duplicated pairs of variable values

Posted in reply to ducman1611

!!!Post test data in the form of a datastep using the code window which is the {i} above post!!!

 

data have;
  input student1 $ student2 $;
datalines;
A B
A C
A D
B A
B C
B D
;
run;

data want;
  set have;
  array student{2};
  call sortc(of student{*});
run;

proc sort data=want nodupkey;
  by student:;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 149 views
  • 2 likes
  • 3 in conversation