DATA Step, Macro, Functions and more

remove duplicate values based on two numerical values

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 103
Accepted Solution

remove duplicate values based on two numerical values

[ Edited ]

Hi All,

 

I have data like this.

 

data:

obsidabcde
11010 0
210100.51
3111.2050.50
4115.901500.50
5113.302000.50
61512600.50
71513000.50
81513600.50

 

want:

obsidabcde
11010 0
210100.51
3111.2050.50
4115.901500.50
5113.302000.50
61512600.50

 

I want  keep only one observation where a=5 and b=1

 

please let me know how to do this  in sas.

 

Thanks in advance.

2   


Accepted Solutions
Solution
‎07-08-2016 12:04 PM
Frequent Contributor
Frequent Contributor
Posts: 103

Re: remove duplicate values based on two numerical values

Answer: the follwing code gives what i want.

 

Proc sort data= data out= want;

by id a b e;

run;

 

 

Thanks forum.

View solution in original post


All Replies
Super User
Posts: 11,343

Re: remove duplicate values based on two numerical values

Probably the easiest if the file is not extremely large is

 

Proc sort data=have out=want noduprecs;

   by id;

run;

Frequent Contributor
Frequent Contributor
Posts: 103

Re: remove duplicate values based on two numerical values

I have updated the dataset, what if several variables like var3 exist in the dataset?
Super User
Posts: 11,343

Re: remove duplicate values based on two numerical values

You may need to post a more complete example if your data is more complex.

 

 

1 2 3 4 5

1 2 3 6 6   <only var3 duplicates does this get deleted?>

1 2 3 4 6   <only var3 and var4 duplicate the first, does this get deleted?>

1 2 3 4 5  <all of var3, var 4 and var5 duplicate the first, the original proc sort solution would work>

Solution
‎07-08-2016 12:04 PM
Frequent Contributor
Frequent Contributor
Posts: 103

Re: remove duplicate values based on two numerical values

Answer: the follwing code gives what i want.

 

Proc sort data= data out= want;

by id a b e;

run;

 

 

Thanks forum.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 240 views
  • 0 likes
  • 2 in conversation