DATA Step, Macro, Functions and more

Calculate five days average from current date

Reply
New Contributor
Posts: 3

Calculate five days average from current date

Hi,

 

I have a dataset like presented below:

 

Brands   Date          Sales    QTY     %Delivery

Adidas  5/15/2017   14000    19         45

Adidas  5/15/2017    1000     12         20

Adidas  5/16/2017   10000     5          35

Adidas  5/17/2017    6000     8           20

Adidas  5/18/2017    8000    17          18

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: 734

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: 19,770

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: 19,770

Re: Calculate five days average from current date

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

If not, please explain how.

Super User
Posts: 11,343

Re: Calculate five days average from current date

Show what your desired output for the example data should look like.

Ask a Question
Discussion stats
  • 6 replies
  • 174 views
  • 1 like
  • 4 in conversation