我有一个如下所示的数据集:
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;
到目前为止,我的代码如下所示:
data ReferenceRateContract;
set refratecontract;
*arrays for years and flags;
array _year(2017:2020) year2017-year2020;
array _flag(2017:2020) flag2017-flag2020;
*loop over array;
if &FixedorFloating=1;
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;
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*i)),, 'kd')
then _flag(i)=1;
else _flag(i)=0;
end;
drop i;
run;
该代码适用于原始 if 函数,但我想通过引入 else if FixedorFloating=0 来使其更具动态性。
我还希望使我的函数能够破译 ID 是否在 ID 的一年 +2i 年。IE
if ID=2017 - i'd like a 1 for years 2017, 2019. For ID=2018,
I'd like a 1 for 2018, 2020 and so on hence the
year(I-2*I)
我不确定这是合理的还是不正确的。
日志的错误如下所示:
82 else if &fixedorfloating=0;
____
160
ERROR 160-185: No matching IF-THEN clause.
84 then do i=&dateoflastrepricing to hbound(_year);
____
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
91 else _flag(i)=0;
92 end;
___
161
ERROR 161-185: No matching DO/SELECT statement.
我假设 if do 后跟 else-if do 的结构不正确。