2017-09-27 141 views
-1

我面臨着一點邏輯死角。想過要在論壇上發帖尋求幫助。根據優先級選擇日期範圍

我有以下數據集。

data have1; 
input case action_in_date action_out_date priority; 
cards; 
100 28-MAY-2015 29SEP2015 02 
100 04-SEP-2015 27NOV2015 03 
100 27-NOV-2015 17SEP2016 04 
; 
run; 

data have2; 
input case post_date amount; 
cards; 
100 18-SEP-2015 250 
100 19-SEP-2015 100 
100 30-NOV-2015 300 
; 
run; 

現在,發佈日期在have2第一數據集2行(18-SEP-2015和19-SEP-2015)具有在對此商品有1數據集兩個日期範圍之間落入後的日期。我e。 2015年5月28日至2015年29月20日以及2015年9月4日和2015年2月27日。但我希望把錢分配給最高優先級。即在04年9月 - 2015年和27NOV2015之間,其優先級爲03.我期待的輸出是低於

/輸出;/ 100 04-SEP-2015 27NOV2015 03 350 100 27-NOV-2015 17SEP2016 04 300 ;

任何幫助,高度讚賞。

回答

0

這是否可以解決您的問題? (不肯定我完全理解這個問題)

proc sql; 
create table allocation as 
select b.case, a.action_in_date, a.action_out_date, a.priority, b.post_date, b.amount 
from have1 a RIGHT JOIN have2 b 
on a.case=b.case and a.action_in_date<=b.post_date<=a.action_out_date 
group by b.case, b.post_date 
having a.priority=max(a.priority); 
quit; 

這裏是關於分配數據集視圖:

enter image description here

順便說一句,我建議這個代碼來創建對此商品有1和have2:

data have1; 
informat action_in_date date9. action_out_date date9.; 
format action_in_date date9. action_out_date date9.; 
input case action_in_date action_out_date priority; 
cards; 
100 28MAY2015 29SEP2015 02 
100 04SEP2015 27NOV2015 03 
100 27NOV2015 17SEP2016 04 
; 
run; 

data have2; 
informat post_date date9.; 
format post_date date9.; 
input case post_date amount; 
cards; 
100 18SEP2015 250 
100 19SEP2015 100 
100 30NOV2015 300 
; 
run;