I am trying to sum up the past 4 weeks forecast vs sales data with each week starting on a monday.
For reference today is 8/6 so i want to start collecting their weekly sales and forecast for 7/5 going up until previous week monday, 7/26. I eventually plan to sum this 4wk forecast into one row using a do until last. statement grouping by Store and SKU to where i can use a put statement to make a new column to signal if they sold more than they forecasted or less. For instance lets pretend they had the below data
|Mon_DT |STORE |SKU |wk_FCST|wk_Sales|
|05July21:00:00:00 | 5 | abc | 10 | 12 |
|12July21:00:00:00 | 5 | abc | 10 | 16 |
|19July21:00:00:00 | 5 | abc | 10 | 7 |
|26July21:00:00:00 | 5 | abc | 10 | 12 |
with the do until last. the forecast will read as 40 and sales as 47 and ill say if sales < forecast then LOWforecast = 'Y';
However, I am having trouble just getting the between statement to work to pull only the last 4 weeks (Starting on monday).
DATA Getweeks;
StartOversell = intnx('week.2',today(),-4);
endoversell = intnx('week.2',today(),-1);
format StartOversell yymmdd10.;
format endoversell yymmdd10.;
Run;
Proc sql;
connect to odbc (dsn='****' uid='****' pwd='***');
create table work.Forecast1 as select distinct * from connection to odbc
(select MON_DT as DATE, Store_Number as Store, PROD_PKG_ID as SKU, FCST AS WK_FCST, SALES AS WK_sales, DIFF_QTY
From FCST
where Mon_DT >= 'StartOversell'd and Mon_DT <= 'endoversell'd );
disconnect from odbc;
quit;
I tried to use a macro variable as well but no luck.