DATA Step, Macro, Functions and more

Creating snapshots at specific points in time.

Reply
Occasional Contributor
Posts: 9

Creating snapshots at specific points in time.

[ Edited ]

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.

 


SAS.PNG
Respected Advisor
Posts: 4,173

Re: Creating snapshots at specific points in time.

Posted in reply to adamhyman

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;

https://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0g056g35ez8son1sfa...

 

Occasional Contributor
Posts: 9

Re: Creating snapshots at specific points in time.

Thanks for your response.

Please see the picture for what I'm trying to do.

I'm looking for the SQL logic to join the tables together.

Thanks!

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Respected Advisor
Posts: 4,173

Re: Creating snapshots at specific points in time.

Posted in reply to adamhyman

@adamhyman

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.

Ask a Question
Discussion stats
  • 3 replies
  • 151 views
  • 0 likes
  • 2 in conversation