BookmarkSubscribeRSS Feed
adamhyman
Calcite | Level 5

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
3 REPLIES 3
Patrick
Opal | Level 21

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...

 

adamhyman
Calcite | Level 5
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. -##
Patrick
Opal | Level 21

@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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 935 views
  • 0 likes
  • 2 in conversation