how to find out the avg for each week

Accepted Solution Solved
Reply
Contributor
Posts: 56
Accepted Solution

how to find out the avg for each week

only one variable sales for 31 days,need average for each week..



regards

Shiva


Accepted Solutions
Solution
‎02-10-2014 12:51 PM
Respected Advisor
Posts: 3,124

Re: how to find out the avg for each week

You bet ya.

data want;

  array t(7) _temporary_;

  do i=1 to 7 until (last);

  set have end=last;

t(i)=sales;

if i=7 or last then AVG=mean (of t(*));

output;

  end;

  call missing(of t(*));

  keep sales avg;

run;

Haikuo

View solution in original post


All Replies
Super User
Posts: 10,490

Re: how to find out the avg for each week

Do you have a date variable and sales for each day with sales? Or do you have a single variable that is an aggregate total of sales for 31 days?

You may also want to consider how you define week, Sunday to Saturday, Monday to Sunday, or other start/end.

It would be helpfule if you could post some example data, even if dummy values, and the expected output.

Super User
Posts: 17,792

Re: how to find out the avg for each week

Assuming you have two variables, one is the date, formatted as a SAS date and one is a price then you can do something like the following:

Basically format your date to be a week. Look into the options for formatting your date as a week - WeekW, WeekV, WeekU etc.

proc means data=have mean;

class date_var;

var sales;

format date_var weekw11.;

output out=want mean(sales)=avg_sales;

run;

Contributor
Posts: 56

Re: how to find out the avg for each week

only one variable sales for 31 days,need average for each week

means avg for every 7 days

no date variable or any other

we must create 2nd column with 4-5 rows of avgs

Respected Advisor
Posts: 3,124

Re: how to find out the avg for each week

Not sure if this is what you want:

data have;

do sales=1 to 31;

  output;

end;

run;

data want;

  array t(7) _temporary_;

  do i=1 to 7;

  set have;

t(i)=sales;

  end;

  AVG=mean (of t(*));

  week=_n_;

  output;

  call missing(of t(*));

  keep avg week;

run;

Haikuo

Contributor
Posts: 56

Re: how to find out the avg for each week

can i get below output plz ?

sales avge
1
2
3
4
5
6
74
8
9
10
11
12
13
1411
15
16
17
18
19
20
2118
22
23
24
25
26
27
2825
29
30
3130
Solution
‎02-10-2014 12:51 PM
Respected Advisor
Posts: 3,124

Re: how to find out the avg for each week

You bet ya.

data want;

  array t(7) _temporary_;

  do i=1 to 7 until (last);

  set have end=last;

t(i)=sales;

if i=7 or last then AVG=mean (of t(*));

output;

  end;

  call missing(of t(*));

  keep sales avg;

run;

Haikuo

Contributor
Posts: 56

Re: how to find out the avg for each week

Thank you Haikuo

regards

Shiva

Super User
Posts: 17,792

Re: how to find out the avg for each week

PS, this should have been your first post Smiley Happy

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 345 views
  • 3 likes
  • 4 in conversation