2
votes

I have a dataset of transactional data per week. (quantity, price, week, etc.) However in the dataset i have two prices for the same week. eg two observations for week 28 (one at price 5.03 and one at price 5.20)

what i want to do is calculate the weighted average price depending on the quantity and sum the quantity for the two different obs so that i have only one obs for week 28.

this happens frequently so i would like to be able to do this quickly without editing manually all prices and quantities.

Oh and this is in SAS btw!

Thanks!

1

1 Answers

4
votes

PROC SUMMARY with the WEIGHT statement applied against price will calculate this for you.

proc summary data=have nway;
class week;
var quantity;
var price / weight=quantity;
output out=want (drop=_:) sum(quantity)= mean(price)=;
run;