DATA Step, Macro, Functions and more

flagging duplicate values

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

flagging duplicate values

data:

 

 

IDab
1102
120014.4
14005
1600

5

want:

 

IDabc (flag)
11020
120014.40
140050
160051

 

So,  variable b has same value 5 in rows 3 and 4. I need to flag first value (row 3)as 0 and subseqent rows containing value 5 as 1.

 

Thank you.


Accepted Solutions
Solution
‎07-11-2016 09:23 AM
Super Contributor
Posts: 441

Re: flagging duplicate values

How about this then:

proc sort data=have;
   by id b;
run;
data want;
   set have;
   by id b;
   c = 0;
   if not first.b and b=5 then c=1;
run;

- Jan

 

 

View solution in original post


All Replies
Super Contributor
Posts: 441

Re: flagging duplicate values

This is my 2 cents. Depending on what you'd like to do with variable a your final version can differ. But the use of first. will be my recommendation.

proc sort data=have;
   by id b;
run;
data want;
   set have;
   by id b;
   if first.b then c=0;
   else c=1;
run;

Regards,

- Jan.

 

Frequent Contributor
Frequent Contributor
Posts: 103

Re: flagging duplicate values

Posted in reply to jklaverstijn

You code works but I need to flag only  one numeric value 5.  For instance, if there are duplicate 8 values , there is no need to flag

Solution
‎07-11-2016 09:23 AM
Super Contributor
Posts: 441

Re: flagging duplicate values

How about this then:

proc sort data=have;
   by id b;
run;
data want;
   set have;
   by id b;
   c = 0;
   if not first.b and b=5 then c=1;
run;

- Jan

 

 

Frequent Contributor
Frequent Contributor
Posts: 103

Re: flagging duplicate values

Posted in reply to jklaverstijn

Thanks. It works Smiley Happy

Super Contributor
Posts: 441

Re: flagging duplicate values

Good to hear. Glad to be of help. Please do not hesitate to flag the question as resolved.

 

Regards Jan.

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 299 views
  • 1 like
  • 2 in conversation