Using Proc Mean/Summary

Reply
Contributor
Posts: 23

Using Proc Mean/Summary

I have a dataset that looks like:

Frequency       Week       ID       Year/Quarter       Weight      Segment       Daypart1      Daypart2      Daypart3

4                    1               1          1                        10          A                    0               2                    2

1                    1               2          1                         11          B                    1               0                    0

3                    1               3          1                         9          C                    0               0                    3

0                    1               4          1                         9          B                    0               0                    0    

9                    1               5          1                         12          A                  3               3                    3

3                    1               6          1                         11          C                    1               0                    2

5                    2               1          2                         10          A                   3               2                    0

7                    2               2          2                         11          B                    2               2                    3

2                    2               3          2                         10          C                    1               0                    1

4                    2               4          2                         9          B                    2               1                    1

0                    2               5          2                         11          A               0                    0                    0

7                    2               6          2                         10          C               3                    3                    1

I'm looking to get a weighted average number of IDs per week, by Frequency, Year/Quarter and Segment.  The total IDs and Daypart values should be multiplied by the weights.  And the weights vary by Year/Quarter

So I want an output that looks like:

Frequency     Year/Quarter     Segment     Average_Weekly_Weighted_IDs     Average_Weekly_Weighted_Daypart1     Average_Weekly_Weighted_Daypart2     Average_Weekly_Weighted_Daypart3

0                    1                    B

1                    1                    B

3                    1                    C

4                    1                    A

9                    1                    A

0                    2                    A

2                    2                    C

4                    2                    B

5                    2                    A

7                    2                    B

7                    2                    C

I think this is possible with Proc Means, maybe in two steps (first you sum up the weights by week, then do an average of them over the weeks).  But I don't know where to start.  Any help would be awesome!

Grand Advisor
Posts: 10,211

Re: Using Proc Mean/Summary

Have you tried:

proc means data=have mean;

class frequency year/quarter segment;

weight weight;

var daypart1 daypart2 daypart3;

run;

If your data doesn't have more than one record for combinations of frequency year/quarter and segment, which is what your example data shows, I don't see what you are actually going to average.

You need to calculate a few of these by hand and show us what you are expecting to get for output.

Contributor
Posts: 23

Re: Using Proc Mean/Summary

I haven't tried that.  I'll give it a shot.  Thanks!

But yes, there are repeats.  In the data example above I only included 1 repeating combination (Frequency=3, Week=1, Year/Quarter=1, Segment=C), but there will be thousands in the dataset I have.

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