DATA Step, Macro, Functions and more

Replicate rows based on weight

Reply
Contributor
Posts: 25

Replicate rows based on weight


Hi,

Now I have a table with 5000 contracts and each contract has different membership. There is a metric measuring the performance of that contract.

Contract_id      membership      metric

H4510               2000                  90%

H0028               5230                  80%

H2309               2341                  95%

.....                    .....                      .....

Now I want to replicate each contract row by membership-times. For example, replicate the first row (H4510) by 2000 times and second row (H0028) by 5230 times and so on.

Does anyone know how to do that?

Thank you so much!

Contributor
Posts: 45

Re: Replicate rows based on weight

You can use this.....

data have;                       

Input contid $ membship metric $;

datalines;                       

H4510 2 90                       

H0028 5 80                       

H2309 2 95                       

;                                

data want(drop=i);               

set have;                        

do i=1 to membship;              

output;                          

end;                             

run;                             

Super User
Posts: 10,474

Re: Replicate rows based on weight

For many analysis steps you may be able to use your membership variable as a FREQ variable.

Ask a Question
Discussion stats
  • 2 replies
  • 194 views
  • 0 likes
  • 3 in conversation