Hi All, I have got a datset as below %let report_month = %sysfunc(putn(%sysfunc(today()),monyy7.)); %let report_date = %sysfunc(putn(%sysfunc(today()),date9.)); %let report_date_beg = %sysfunc(putn(%sysfunc(intnx(month,"&report_date"d,0,b)),date9.)); %put report_month : &report_month. report_date : &report_date. report_date_beg :&report_date_beg.; data disp_elg; infile datalines dlm = "," dsd; input id $ flag; rep_month = symget("report_month"); datalines; 1111,1 1211,0 1311,0 1411,1 1511,1 1611,1 1711,1 1811,1 1911,0 2011,0 2111,1 ;run; This dataset gives me flag as 1 and 0 per ID and reporting month . I need to produce a dataset and retain a history for 15 months where the varibales would be like mentioned in the target dataset if flag is 1 and count of ipqm1 in last 15 month = 0 then code = ipqm1 else if flag is 1 and count of ipqm1 > 2 in last 10 months then code = ipqm2 else if flag is 1 and code = ipqm1 and diff_month = 1 then code = ipqm2 else if code = ipqm2 and diff_month = 2 then code = ipqm3 else if code = ipqm3 and diff_month = 6 then code = ipqm1 else if (code = ipqm1 and diff_month > 1) or (code = ipqm2 and diff_month > 2) or (code = ipqm3 and diff_month > 6) then code = ipqm1 else "do nothing" So basically we need to set the code depending on the differnce in months and count of particular code in that month diff and the data needs to be produced on a monthly basis and get that appended to create the history. Any support would be highly appriciated Target ID,code,rep_month 1111,ipqm1,dec2018 1211,ipqm1,dec2018 1311,ipqm1,dec2018 1411,ipqm1,dec2018 1511,ipqm1,dec2018 1611,ipqm1,dec2018 1711,ipqm1,dec2018 1811,ipqm1,dec2018 1911,ipqm1,dec2018 2011,ipqm1,dec2018 2111,ipqm1,dec2018 2211,ipqm1,Jan2019 1411,ipqm2,Jan2019 2311,ipqm1,Jan2019 1211,ipqm2,Jan2019 2411,ipqm1,Jan2019 2511,ipqm1,Jan2019 2611,ipqm1,Jan2019 2711,ipqm1,Jan2019 2811,ipqm1,Jan2019 2911,ipqm1,Jan2019 3011,ipqm1,Jan2019 3111,ipqm1,Feb2019 3211,ipqm1,Feb2019 3311,ipqm1,Feb2019 1311,ipqm3,Feb2019 3411,ipqm1,Feb2019 3511,ipqm1,Feb2019 3611,ipqm1,Feb2019 3711,ipqm1,Feb2019 3811,ipqm1,Feb2019 3911,ipqm1,Feb2019
... View more