Help using Base SAS procedures

How to do a weighted count?

New Contributor
Posts: 2

How to do a weighted count?

I have a data set with a list of ID numbers and type of involvement. The types are either "event attendance" or "leadership". I need to create a count for each ID that weights each 'event attendance' as .5 and each "leadership" as 2. How do I do this?

Super User
Super User
Posts: 8,127

How to do a weighted count?

Code a new variable and sum that.

data want ;

  set have;

  if involvement='event attendence' then wt=.5;

else if involvement='leadership' then wt=2;


Super User
Posts: 13,583

How to do a weighted count?

continuing from last post:

Proc freq data=want;

table involvement;

weight wt;


Valued Guide
Posts: 2,191

How to do a weighted count?

and the sql alternative

proc sql ;

   create table summary as select id, sum(


         when  involvement='event attendence' then .5

         when involvement='leadership' then .2

         else 0

      end ) as weighted_count

   from your_data

   group by ID


quit ;

Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation