我有一个如下所示的数据集:
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
e.g。
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;***
答案 0 :(得分:0)
问题是我应该放I - 2
而不是I + 2
另外,我必须更改数组限制,因为我的hbound试图迭代到矩阵的末尾。