I have a dataset which looks like this:
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
I am looking to create an array based on a few inputs:
%let FixedorFloating = '1 or 0';
%let Repricingfrequency = n Years;
%let LastRepricingDate = 'Date'n;
The array criteria is such that if ID= Year +2i then 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
My code is currently, I'm having issues with year i+2 (highlighted in red) but year(i) works fine.
data ReferenceRateContract;
set refratecontract;
*arrays for years and flags;
array _year(2017:2022) year2017-year2022;
array _flag(2017:2022) flag2017-flag2022;
*loop over array;
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;
run;
data referenceratecontract;
set referenceratecontract;
keep flag2017--flag2020;
run;
Looking for a way to flag based on Id= Year + 2i, TIA
***else if put(ID, 4.) = compress(vname(_year(i+2)),, 'kd') then _flag(i)=1;***