user634455
user634455

Reputation: 115

SAS replacing duplicate values

I have a data set that has duplicate values of v1. I would like v2 values to be replaced by the first value of v2.

Data one;  
v1   v2  
1    20  
1    23  
1    21  
2    36  
3    51  
4    44  
4    20  

I would like data=one to be changed to this:

Data one;  
v1    v2  
1     20  
1     20  
1     20  
2     36  
3     51    
4     44    
4     44

what procedure do I need to use?

Upvotes: 0

Views: 212

Answers (1)

BellevueBob
BellevueBob

Reputation: 9618

A data step will do (assuming the data is already sorted the way you want):

data one;
   set one;
      by v1;
   if first.v1 
      then keeper=v2;
      else v2=keeper;
   retain keeper;
   drop keeper;
run;

Upvotes: 2

Related Questions