Hello everyone,
I'm working on little complex problem, converting SAS code to SQL. I have attached the sample data. Data is order by Account number and Month end date.
Here is the SAS code:
by accountnumber;
retain status;
if first.accountnumber = 1 then status = 0;
if lag(accountstatusdescription) = 'Active' AND accountstatusdescription in ('Chargeoff', 'Closed', 'Non-Accrual') then status = 1;
if status > 0 then status + 1;
if lag(accountstatusdescription) = 'Active' AND accountstatusdescription in ('Chargeoff', 'Closed', 'Non-Accrual') then status = status - 1;
Problem : How to use first. variable and retain in SQL/Alteryx?.
I'm able to achieve the later part in after if first.accountnumber = 1 then status = 0 Alteryx using multi-row formula. Like this :
IF [Account status Desc]='Active'
THEN 0
ELSEIF [Account status Desc]!='Active' AND [Account status Desc]!=[Row-1:Account status Desc]
THEN 1
ELSE [Row-1:Status Alteryx]+1
ENDIF
But what I need is if the first. account number then status =0 and that status will retain, please see row 24 in the spreadsheet.
Please let me know if I didn't explain it properly or need more information.
Thank you for your help in advanced!