I am trying to identify when a record first goes into default and retain that date as a default date. If the record comes out of default and then goes back into default that would reset the default date. I cannot figure out how to make this happen. Below are have and want datasets with my progress up to this point. Thank You, data data; infile cards dsd dlm=','; informat record_date mmddyy10.; format record_date mmddyy10.; input power_id $ record_date default_reason $; cards; test1,8/31/2013, test1,9/30/2013,PD test1,10/31/2013,PD test1,11/30/2013,PD test1,12/31/2013, test1,1/31/2014, test1,2/28/2014, test1,3/31/2014,PD test1,4/30/2014,PD test1,5/31/2014, test1,6/30/2014, test1,7/31/2014, test1,8/31/2014, test1,9/30/2014, test1,10/31/2014, test1,11/30/2014, test1,12/31/2014, test1,1/31/2015, test2,2/28/2015,PD test2,3/31/2015,PD test2,4/30/2015, test2,5/31/2015, test2,6/30/2015, test2,7/31/2015, test2,8/31/2015, test2,9/30/2015, test2,10/31/2015, test2,11/30/2015, test2,12/31/2015,PD test2,1/31/2016,PD test2,2/29/2016, test2,3/31/2016, test2,4/30/2016, test2,5/31/2016, test2,6/30/2016, ; run; data have(keep=power_id record_date default_reason pass_date pass_count first_default_flag); format pass_date mmddyy10.; retain pass_date first_default_flag; set data; by power_id; pass_count + 1; if first.power_id or default_reason ne '' then pass_date = .; if first.power_id then pass_count = 0; /*account for records that do not start in default*/ if first.power_id and default_reason = '' then first_default_flag = 0; else if default_reason ne '' then first_default_flag = 1; if first_default_flag = 1 then do; if first.power_id then pass_date = .; if first.power_id then pass_count = 0; if default_reason ne '' then pass_count = 0; if pass_count = 7 then pass_date = record_date; if pass_count > 6 and default_reason ne '' then pass_date = .; end; run; data want; infile cards dsd; informat record_date pass_date default_date mmddyy10.; format record_date pass_date default_date mmddyy10.; input power_id $ record_date default_reason $ pass_date default_date first_default_flag pass_count; cards; test1,08/31/2013,,,,0,0 test1,09/30/2013,PD,,09/30/2013,1,0 test1,10/31/2013,PD,,09/30/2013,1,0 test1,11/30/2013,PD,,09/30/2013,1,0 test1,12/31/2013,,,09/30/2013,1,1 test1,01/31/2014,,,09/30/2013,1,2 test1,02/28/2014,,,09/30/2013,1,3 test1,03/31/2014,PD,,09/30/2013,1,0 test1,04/30/2014,PD,,09/30/2013,1,0 test1,05/31/2014,,,09/30/2013,1,1 test1,06/30/2014,,,09/30/2013,1,2 test1,07/31/2014,,,09/30/2013,1,3 test1,08/31/2014,,,09/30/2013,1,4 test1,09/30/2014,,,09/30/2013,1,5 test1,10/31/2014,,,09/30/2013,1,6 test1,11/30/2014,,11/30/2014,09/30/2013,1,7 test1,12/31/2014,,11/30/2014,09/30/2013,1,8 test1,01/31/2015,,11/30/2014,09/30/2013,1,9 test2,02/28/2015,PD,,02/28/2015,1,0 test2,03/31/2015,PD,,02/28/2015,1,0 test2,04/30/2015,,,02/28/2015,1,1 test2,05/31/2015,,,02/28/2015,1,2 test2,06/30/2015,,,02/28/2015,1,3 test2,07/31/2015,,,02/28/2015,1,4 test2,08/31/2015,,,02/28/2015,1,5 test2,09/30/2015,,,02/28/2015,1,6 test2,10/31/2015,,10/31/2015,02/28/2015,1,7 test2,11/30/2015,,10/31/2015,02/28/2015,1,8 test2,12/31/2015,PD,,12/31/2015,1,0 test2,01/31/2016,PD,,12/31/2015,1,0 test2,02/29/2016,,,12/31/2015,1,1 test2,03/31/2016,,,12/31/2015,1,2 test2,04/30/2016,,,12/31/2015,1,3 test2,05/31/2016,,,12/31/2015,1,4 test2,06/30/2016,,,12/31/2015,1,5 ; run;
... View more