我有一个如下所示的数据集:
ID 2017 2018 2019 2020
2017 30 24 20 18
2018 30 24 20 18
2019 30 24 20 18
2020 30 24 20 18
我正在寻找基于一些输入创建一个数组:
%let FixedorFloating = '1 or 0';
%let Repricingfrequency = n Years;
%let LastRepricingDate = 'Date'n;
数组标准是这样的,如果 ID= Year +2i 然后 flag = 1
例如
ID = 2017 then flag =1 for Years 2017 and 2019, 0 otherwise
ID = 2018 then flag = 1 for Years 2018 and 2020, 0 otherwise
ID = 2019 then flag = 1 for Year 2019 , 0 otherwise
ID = 2020 then flag = 1 for year 2020, 0 otherwise
我的代码目前是第 i+2 年(以红色突出显示)有问题,但第(i)年工作正常。
data ReferenceRateContract;
set refratecontract;
*arrays for years and flags;
array _year(2017:2022) year2017-year2022;
array _flag(2017:2022) flag2017-flag2022;
*循环遍历数组;
if &FixedorFloating=1
then do i=&dateoflastrepricing to hbound(_year);
/*check if year matches year in variable name*/
if put(ID, 4.) = compress(vname(_year(i)),, 'kd')
then _flag(i)=1;
else _flag(i)=0;
end;
else if &fixedorfloating=0
then do i=&dateoflastrepricing to hbound(_year);
if put(ID, 4.) = compress(vname(_year(i)),, 'kd')
then _flag(i)=1;
else if put(ID, 4.) = compress(vname(_year(i+2)),, 'kd')
then _flag(i)=1;
else _flag(i)=0;
end;
drop i;
跑;
data referenceratecontract;
set referenceratecontract;
keep flag2017--flag2020;
run;
寻找一种基于 Id= Year + 2i, TIA 的标记方式
***else if put(ID, 4.) = compress(vname(_year(i+2)),, 'kd') then _flag(i)=1;***