## remove duplicate values based on two numerical values

Solved
Frequent Contributor
Posts: 106

# remove duplicate values based on two numerical values

[ Edited ]

Hi All,

I have data like this.

data:

 obs id a b c d e 1 1 0 1 0 0 2 1 0 1 0 0.5 1 3 1 11.2 0 5 0.5 0 4 1 15.9 0 150 0.5 0 5 1 13.3 0 200 0.5 0 6 1 5 1 260 0.5 0 7 1 5 1 300 0.5 0 8 1 5 1 360 0.5 0

want:

 obs id a b c d e 1 1 0 1 0 0 2 1 0 1 0 0.5 1 3 1 11.2 0 5 0.5 0 4 1 15.9 0 150 0.5 0 5 1 13.3 0 200 0.5 0 6 1 5 1 260 0.5 0

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

please let me know how to do this  in sas.

2

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

## 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.

All Replies
Super User
Posts: 13,563

## 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
Posts: 106

## 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: 13,563

## 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
Posts: 106

## 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.

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