New Contributor
Posts: 3

# Calculate five days average from current date

Hi,

I have a dataset like presented below:

Brands   Date          Sales    QTY     %Delivery

Nike     5/16/2017    6000     8            12

Nike      5/17/2017    8000    13          10

Nike    5/18/2017    8000    13             11

-

-

I have data like above for different brands and their delivery percentage. The problem is I would like to loop through all the 100 brands and create a flag for each brand where %Delivery (last column) is 40% more than the last 5 day average.

Thank you

PROC Star
Posts: 1,283

## Re: Calculate five days average from current date

Do you want as many records as in your current dataset with a 0/1 flag or do you want 1 record for each brand?

New Contributor
Posts: 3

## Re: Calculate five days average from current date

I want one record for each brand. The business problem is if current %delivery is more than last five day's average then create a flag 1 else zero. and then output it

Super User
Posts: 23,776

## Re: Calculate five days average from current date

http://blogs.sas.com/content/iml/2016/01/27/moving-average-in-sas.html

If you can assume that you have a continuous series, the best solutions are above.

Otherwise you need to first figure out how to deal with breaks in your data.

New Contributor
Posts: 3

## Re: Calculate five days average from current date

I do not have a continous series. I need to calculate this by each brand.

Super User
Posts: 23,776

## Re: Calculate five days average from current date

Did none of the solutions in the blog work for you?