Please see the attached picture, which shows my 2 input tables and the output that I would like to create.
I have a table which recorded the forecast at different points in time.
I did 2 forecasts for item AAA, on 12/6 and 12/7.
I did 2 forecasts for item BBB, on 12/6 and 12/13.
I would like to create a summary table, which shows the forecast, as of the dates in the Date table.
So, for date 12/11:
AAA's latest forecast was on 12/7.
BBB's latest forecast was on 12/6.
For date 12/18:
AAA's latest forecast was on 12/7.
BBB's latest forecast was on 12/13.
Any advice on how to create the summary in an efficient way would be greatly appreciated.
Calendar function intnx() can do the job for you.
data sample;
format date_of_forcast forcast_week date9.;
date_of_forcast='07dec2016'd;
forcast_week=intnx('week.2',date_of_forcast,0,'e');
run;
If you want actual code for your data then don't just post a picture but post SAS datasteps creating representative sample data.
As for the joining: The only thing you need to do is to shift in your first table the date to the Sunday. After that you can join the two tables over the Item and Sunday date. The code I've posted demonstrates how you can shift the date_of_forcast to the Sunday date - try to understand it.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.