BookmarkSubscribeRSS Feed
hvempati
Obsidian | Level 7

I have two tables. 

Table A

id start_dtend_dt
15  05Sep2018 12-Sep-18
15  10Sep2018 20-Sep-18
15  11Sep2018 12-Sep-18
16  05Sep2018 20-Sep-18
17  06Sep2018 6-Sep-18
17 12Sep2018  20Sep2018

 

Table B

DatesSales
05Sep201881
06Sep201895
07Sep201821
08Sep201823
09Sep201848
10Sep201878
11Sep201813
12Sep201810
13Sep201891
14Sep201860
15Sep201830
16Sep201881
17Sep20184
18Sep201811
19Sep20185
20Sep201877

 

 I need to join these two tables such that it adds all the sales within the date range with respect to id. If there are multiple entry with id for same date, it needs to be divided equally among the id's.

 

 

Output table calculation would look like this- 

id start_dtend_dtsales
15  05Sep2018 12-Sep-1881+95+21+23+48+78/2+13/3+10/3
15  10Sep2018 20-Sep-1878/2+13/3+10/3+91+60+30+81+4+11+5+77
15  11Sep2018 12-Sep-1813/3+10/3
16  05Sep2018 20-Sep-1881+95+21+23+48+78+13+10+91+60+30+81+4+11+5+77
17  06Sep2018 6-Sep-1895
17 12Sep2018  20Sep201810+91+60+30+81+4+11+5+77

 

and the output table should look like this-

 

id start_dtend_dtsales
15  05Sep2018 12-Sep-18314.6667
15  10Sep2018 20-Sep-18405.6667
15  11Sep2018 12-Sep-187.666667
16  05Sep2018 20-Sep-18728
17  06Sep2018 6-Sep-1895
17 12Sep2018  20Sep2018

369

 

 

Any help is highly appreciated and would love to clarify if you have any questions.

 

Thank you. 

 

2 REPLIES 2
LinusH
Tourmaline | Level 20
Without calculating on your example I would simply suggest a join with a BETWEEN - AND criteria, and then just SUM() - GROUP BY.
Data never sleeps
hvempati
Obsidian | Level 7

But is there not a way to do this type of join or can I split the data and then join?

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 657 views
  • 0 likes
  • 2 in conversation