Reputation: 1
I have 1500+ observations in a dataset with about 350 unique subject ids. I am trying to create weighted averages of a variable for all the observations for each unique subject id. I'm not sure how to code a procedure that could automate this process where I didn't need to create the variable one at a time for all 350 subject ids. Thoughts?
Upvotes: 0
Views: 56
Reputation: 21294
Assuming you have something like the following:
Data have;
input SubjID $ varMeasure varWeight;
cards;
01 25 1
01 30 2
01 40 3
02 25 2
02 30 1
02 40 3
;;;;
run;
You can use Proc means and specify your weight:
proc means data= have nway noprint;
class subjid;
var varMeasure;
weight varWeight;
output out=want mean = weighted_mean;
run;
Upvotes: 1