Help using Base SAS procedures

How to use proc sort nodupkey??

Reply
Occasional Contributor
Posts: 10

How to use proc sort nodupkey??

I have a dataset that has some duplicate observations as follows:

 

ID  VAR1 VAR2 VAR3

1      a        .          .

1      a        b        c

2      d        e         f

3      g        .         .

 

var1, var2 and var3 are numeric.

I want to delete the first observation. I use the following code:

 

Proc sort data=have out=want nodupkey;

by ID VAR1;

run;

 

However, this code delete the second observation, instead of the first one.

Any one knows what I should do to delete the first observations?? Thanks in advance!

Super User
Posts: 10,028

Re: How to use proc sort nodupkey??

[ Edited ]
Posted in reply to OceanDream
data want;
 set have;
 by ID VAR1;
 if last.VAR1;
run;
Occasional Contributor
Posts: 10

Re: How to use proc sort nodupkey??

Thank you! Keshan!

Super User
Posts: 5,429

Re: How to use proc sort nodupkey??

Posted in reply to OceanDream
@Ksharp's code works if your rule is "in case of duplictes remove the first observation".
But your sample data illustrates rather a rule that says remove the observation that has missing values on the non id variables. If this is the case, you need to presort your data to be sure to get the desired result.
Data never sleeps
Ask a Question
Discussion stats
  • 3 replies
  • 624 views
  • 1 like
  • 3 in conversation