Мои данные в формате ниже, и я хочу создать код ниже, который зависит от этих данных в коде Python.Мне трудно продолжать.
data out1 out2;
set Input
if excl=0 and strip(segment) ne "segment";
if intck("month",vardate,'30Jun2008'd)<0 and intck("month",vardate,'31Mar2010'd)>=0 then do;
Rec=1;
red=0;
end;
else if intck("month",vardate,'31Mar2010'd)<0 and intck("month",vardate,'30Sep2013'D)>=0 then do;
Rec=0;
red=1;
end;
else do;
Rec=0;
red=0;
end;
if vardate in ('30Jun2008'd,'30Jun2009'd,'30Jun2012'd,'30Jun2014'd) or intck("month",vardate,'30Jun2016'd)<=0 then output out2;
else output out1;
run;
![enter image description here](https://i.stack.imgur.com/w42zS.png)
Я пытался написать этот фрагмент кода, чтобы начать, но не сработал. Теперь это мойкод.
recession = 0
recovery = 0
if data['excl_flg'] == 0 and data['segment'] != 'not modeled':
if (data['snapdate'].dt.to_period('M') - '2008-06-30'.dt.to_period('M')) < 0 & (data['snapdate'].dt.to_period('M') - '31Mar2010'.dt.to_period('M') >= 0:
recession = 1
elif (data['snapdate'].dt.to_period('M') - '31Mar2010'.dt.to_period('M')) < 0 and (data['snapdate'].dt.to_period('M') - '30Sep2013'.dt.to_period('M')) >= 0:
recovery = 1