Help using Base SAS procedures

How to do a weighted count?

Reply
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: 6,500

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;

run;

Super User
Posts: 10,500

How to do a weighted count?

continuing from last post:

Proc freq data=want;

table involvement;

weight wt;

run;

Valued Guide
Posts: 2,175

How to do a weighted count?

and the sql alternative

proc sql ;

   create table summary as select id, sum(

      case

         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
  • 1408 views
  • 0 likes
  • 4 in conversation