我有两个数据集Set1和Set2。
Set1数据集的列为Curr_Dt: -
Set1
Curr_Dt
23/04/1998
01/01/2017
01/12/2018
10/10/2010
Set2数据集有3列St_Dt,End_Dt,Ind
St_Dt End_Dt Ind
01/11/2018 31/12/2018 N
01/01/1998 31/05/1998 N
30/11/2016 02/02/2017 N
如果Set1的Curr_Dt落在Set2的St_Dt和End_Dt之间,我想将Set2数据集的Ind列更新为Y.
答案 0 :(得分:0)
我没有在这里看到一个用于合并的键,所以我假设第一行与第一行一致,因此每个数据集都是如此。
您可以使用简单的数据步骤来完成此操作。
data want;
merge set1 set2;
if st_dt <= curr_dt <= end_dt then
ind = 'Y';
run;
这也假设日期存储为日期而不是字符串。
答案 1 :(得分:0)
创建集
byte[] postBuffer = new UTF8Encoding().GetBytes(postStr);
设置日期格式
data Set1;
length Curr_Dt $10;
input Curr_Dt;
cards;
23/04/1998
01/01/2017
01/12/2018
10/10/2010
;
run;
data Set2;
length St_Dt $10 End_Dt $10 Ind $1;
input St_Dt$ End_Dt$ Ind$;
cards;
01/11/2018 31/12/2018 N
01/01/1998 31/05/1998 N
30/11/2016 02/02/2017 N
30/11/2005 02/02/2005 N
run;
如果来自data Set1;
set Set1;
Curr = input(Curr_Dt, ddmmyy10.);
run;
data Set2;
set Set2;
St = input(St_Dt, ddmmyy10.);
End = input(End_Dt, ddmmyy10.);
run;
的{strong>任何 Curr_Dt
落在Set1
和St_Dt
End_Dt
你得到了
proc sql;
create table Set2 as
select distinct St_Dt, End_Dt,
case when Set1.Curr>Set2.St and Set1.Curr<Set2.End
then 'Y' else 'N' end as Ind
from Set2
left join Set1 on Set1.Curr>Set2.St and Set1.Curr<Set2.End;
run;