Solved
Contributor
Posts: 56

# 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,167

## Re: how to find out the avg for each week

Posted in reply to shivakrishna

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

All Replies
Super User
Posts: 13,542

## Re: how to find out the avg for each week

Posted in reply to shivakrishna

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: 23,724

## Re: how to find out the avg for each week

Posted in reply to shivakrishna

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,167

## Re: how to find out the avg for each week

Posted in reply to shivakrishna

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 7 4 8 9 10 11 12 13 14 11 15 16 17 18 19 20 21 18 22 23 24 25 26 27 28 25 29 30 31 30
Solution
‎02-10-2014 12:51 PM
Respected Advisor
Posts: 3,167

## Re: how to find out the avg for each week

Posted in reply to shivakrishna

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

Thank you Haikuo

regards

Shiva

Super User
Posts: 23,724

## Re: how to find out the avg for each week

Posted in reply to shivakrishna

PS, this should have been your first post

🔒 This topic is solved and locked.

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

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