Thanks to all for your responses. I have stumbled across another problem: data test_new; infile datalines; length ID 8 time 8 default=8; /* read MON YY values as numeric date values */ informat time monyy.; format time monyy.; input ID Time Default; datalines; 1 Jan13 0 1 Feb13 0 1 Mar13 1 1 Apr13 1 1 May13 0 1 Jun13 0 1 Jul13 1 1 Aug13 1 1 Sep13 0 1 Oct13 1 1 Nov13 0 1 Dec13 0 1 Jan14 0 1 Feb14 1 1 Mar14 0 ; run; I am trying to achieve one of the tasks as to find the time between defaults, that is, between April13 and Jul13 we have 2 non defaults and so the duration for non default is 2 months. ID time Default Time between defaults 1 Jan2013 0 1 Feb2013 0 1 Mar2013 1 1 Apr2013 1 1 May2013 0 2 months 1 Jun2013 0 1 Jul2013 1 1 Aug2013 1 1 Sep2013 0 1 month 1 Oct2013 1 1 Nov2013 0 1 Dec2013 0 3 months 1 Jan2014 0 1 Feb2014 1 1 Mar2014 0 I have tried the following code but not going anywhere with it. Thanks in advance!! data time_new; set test_new; format start_date monyy.; format end_date monyy.; previous_default=lag(default); /*previous_month=lag(Time);*/ if default=1 and previous_default =0 then start_date=Time; else if default=0 and previous_default =1 then end_date=time; if default=1 and previous_default=1 then start_date=Time; else if default=0 and previous_default =0 then end_date=Time; if default=1 and previous_default=1 then start_date=Time; else if default=0 and previous_default =1 then end_date=Time; run;
... View more